首页 > 其他 > 详细

Operating System: Three Easy Pieces --- Why It Gets Worse: Shared Data (Note)

时间:2015-11-06 14:36:48      阅读:290      评论:0      收藏:0      [点我收藏+]

The simple thread example we showed above was useful in showing how threads are

created and how they can run in different orders depending on how the scheduler decides

to run them. What it doesn‘t show you, though, is how threads interact when they access

shared data.

          The Heart Of The Problem: Uncontrolled Scheduling

To understand why this happens, we must understand the code sequence that the compiler

generates for the update to counter. In this case, we wish to simple add a number 1 to counter.

Thus, the code sequence for doing so might look something like this (in X86);

mov 0x8049a1c, %eax

add $0x01, %eax

mov %eax, 0x8049a1c

This example assumes that the variable counter is located at address 0x8049a1c. In this

three-instruction sequence, the x86 mov instruction is used first to get the memory value at 

the address and put it into register eax. Then, the add is performed, adding 1 to the contents

of the eax register, and finally, the contents of eax are stored back into memory at the same

address.

Operating System: Three Easy Pieces --- Why It Gets Worse: Shared Data (Note)

原文:http://www.cnblogs.com/miaoyong/p/4942370.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!