You are on page 1of 2

MUNCHEN TECHNISCHE UNIVERSITAT Lehrstuhl f ur Integrierte Systeme

Chip Multicore Processors Tutorial 3


May 15, 2013

3.1: 3-Thread Lock


You have a processor at hand that does not contain any hardware support for locking or atomar operations. Extend Petersons Lock to support three threads. How can this be generalized?

3.2: Locking
In you nd a piece of source code to implement a stack. In a stack, the last written element is read as rst (LIFO). Use the functions mutex_lock(mutex*) and mutex_unlock(mutex*) to make the code thread-safe.

3.3 Spinlocks vs. Blocking Locks


In the context of mutexes, explain what the dierence between spinlocks and blocking locks is.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

#define N 100 int buf [N ] ; int c = 0 ; int a = 1 ; mutex l o c k ; void w r i t e ( int i ) { int tmp ; tmp = c ; while ( tmp==N) { tmp = c ; } buf [ c ] = i ; c = c + 1; } int r e a d ( ) { int r ; int tmp ; tmp = c ; while ( tmp==0) { tmp = c ; } r = buf [ c ] ; c = c 1;

return r ; } Abbildung 1: Source code for 3.2

You might also like