Problem 5. 15 Points - Barriers

Two shared-memory systems use different implementations of the sense-reversal barrier:

Screen Shot 2014-04-29 at 10.14.52 AM.png

Variable locSens is local in each thread, while cntlock, cnt, tot, and rel are

global variables shared by all threads. All these variables start out with zero values,

except of course cntlock (which is correctly initialized using pthread_mutex_init.

Whereas Implementation 1 is correct, Implementation 2 does not. Show a (sequentially

consistent) execution order for two threads (tot is 2) in Implementation 2 that leads to

incorrect behavior. An execution order (interleaving) can be represented as a sequence of

[Core #: Line #] events, using “Work” instead of a line number for actual work between

calls to the barrier, e.g. [C1: L1], [C2: L1], [C1: L2,L3,L4], [C2: L2,L3,L4], [C1: L5],

[C2: L5], [C1: L6], [C2: L6], [C1: L7], [C2: L7], [C1: Work], [C2: Work], [C1: L1], [C2:

L1], etc. leads to correct behavior.


Explain your answer (you do not have to use the entire page, short answers are better):