码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-11-06 14:37:32      阅读:222      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!