- 3
- 0
- 约2.1万字
- 约 105页
- 2018-08-30 发布于湖北
- 举报
What happened? Thus, thread 0’s call to strtok with the third line of the input has apparently overwritten the contents of thread 1’s call with the second line. So the strtok function is not thread-safe.If multiple threads call it simultaneously, the output may not be correct. Copyright ? 2010, Elsevier Inc. All rights Reserved Other unsafe C library functions Regrettably, it’s not uncommon for C library functions to fail to be thread-safe. The random number generator random in stdlib.h. The time conversion function localtime in time.h. Copyright ? 2010, Elsevier Inc. All rights Reserved “re-entrant” (thread safe) functions In some cases, the C standard specifies an alternate, thread-safe, version of a function. Copyright ? 2010, Elsevier Inc. All rights Reserved Concluding Remarks (1) A thread in shared-memory programming is analogous to a process in distributed memory programming. However, a thread is often lighter-weight than a full-fledged process. In Pthreads programs, all the threads have access to global variables, while local variables usually are private to the thread running the function. Copyright ? 2010, Elsevier Inc. All rights Reserved Concluding Remarks (2) When indeterminacy results from multiple threads attempting to access a shared resource such as a shared variable or a shared file, at least one of the accesses is an update, and the accesses can result in an error, we have a race condition. Copyright ? 2010, Elsevier Inc. All rights Reserved Concluding Remarks (3) A critical section is a block of code that updates a shared resource that can only be updated by one thread at a time. So the execution of code in a critical section should, effectively, be executed as serial code. Copyright ? 2010, Elsevier Inc. All rights Reserved Concluding Remarks (4) Busy-waiting can be used to avoid conflicting access to critical sections with a flag variable and a while-loop with an empty body. It can be very wasteful of CPU cycles. It can also be unreliabl
您可能关注的文档
- 关于开关电源和其功率材料的市场和技术动向.doc
- 空调工程和建筑设计.doc
- 星湖奥园建设节能施工方案规范.doc
- 给水排水实验指导书(2012版)(完整).doc
- 论合同法上任意性规范(一)-附件.doc
- 河南省2012年基层畜牧业的技术推广补助项目.pdf
- 第02单元 基础工程质量保证措施详解.doc
- 电气接地施工质量标准与工艺要求.doc
- 消防安全知识培训学习.ppt
- 建设工程承揽合同剖析.doc
- 伟明环保-市场前景及投资研究报告-境内业务稳健运行,印尼市场贡献边际增量.pdf
- 桂东县法院系统招聘考试真题2025.pdf
- 贵州省黔南布依族2026年中考三模物理试题及答案.pdf
- 贵州省黔南州2026年中考语文二模试卷附答案.pdf
- 贵州省铜仁市2026年中考语文二模试卷附答案.pdf
- 2026上半年安徽事业单位联考合肥市庐江县招聘36人备考题库及一套完整答案详解.docx
- 贵州省毕节市2026年中考语文一模试卷附答案.pdf
- 贵州省贵阳市南明区2026年中考语文一模试卷附答案.pdf
- 2026上半年安徽事业单位联考合肥市庐江县招聘36人备考题库及一套参考答案详解.docx
- 贵州省贵阳市白云区2026年中考二模物理试题附答案.pdf
原创力文档

文档评论(0)