For electrical and electronic engineers see ieee

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: such as cnt are a little tricky because the sharing is limited to the functions within their scope, in this case the thread routine. A. Here is the table: Variable instance ptr cnt i.m msgs.m myid.p0 myid.p1 Referenced by main thread? yes no yes yes no no Referenced by peer thread 0 ? yes yes no yes yes no Referenced by peer thread 1? yes yes no yes no yes Notes: ptr: A global variable that is written by the main thread and read by the peer threads. cnt: A static variable with only one instance in memory that is read and written by the two peer threads. B.11. CONCURRENT PROGRAMMING WITH THREADS 735 i.m: A local automatic variable stored on the stack of the main thread. Even though its value is passed to the peer threads, the peer threads never reference it on the stack, and thus it is not shared. msgs.m: A local automatic variable stored on the main thread’s stack and referenced indirectly through ptr by both peer threads. myid.0 and myid.1: Instances of a local automatic variable residing on the stacks of peer threads 0 and 1 respectively. B. Variables ptr, cnt, and msgs are referenced by more than one thread, and thus are shared. Problem 11.3 Solution: [Pg. 576] A. Sequentially consistent. B. Not sequentially consistent because ͽ executes before Ľ . C. Sequentially consistent. D. Not sequentially consistent because ˾ executes before ; . Problem 11.4 Solution: [Pg. 576] The important idea here is that sequential consistency is not enough to guarantee cor...
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