Figure 1123 shows a handy routine that a thread can

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

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 find it helpful to partition the loop code for thread into five 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 defines some total ordering (or interleaving) of the instructions in the two threads....
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online