This preview shows page 1. Sign up to view the full content.
Unformatted text preview: ! ctr=198269672 So what went wrong? To understand the problem clearly, we need to study the assembly code for the counter loop, as shown in Figure 11.9. We will ﬁnd it helpful to partition the loop code for thread into ﬁve parts: ¯ À : The block of instructions at the head of the loop. ¯ Ä : The instruction that loads the shared variable cnt into register %eax , where %eax
value of register %eax in thread . denotes the ¯ Í : The instruction that updates (increments) %eax . ¯ Ë : The instruction that stores the updated value of %eax ¯ Ì : The block of instructions at the tail of the loop. back to the shared variable cnt. Notice that the head and tail manipulate only local stack variables, while contents of the shared counter variable. Ä , Í , and Ë manipulate the 11.4.1 Sequential Consistency
When the two peer threads in badcnt.c run concurrently on a single CPU, the instructions are completed one after the other in some order. Thus, each concurrent execution deﬁnes some total ordering (or interleaving) of the instructions in the two threads....
View Full Document