Lecture 4 - Non-blockinng synchronisation of concurrent shared data structures Flashcards

1
Q

Mutual Exclusion using TestAndSet

A
do {
while ( TestAndSet (&lock ))
; // do nothing but spinning on the lock (busy waiting)
// … critical section
lock = FALSE;
// … remainder section
} while ( TRUE);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Fine-Grained locking

A

A concurrent hashtable with fine-grained locking

1 mutex lock per hash value / list, as operations on different lists are independent

A parallel FIFO queue with k heads.
• Queue items distributed round-robin
over the k subqueues
• Up to k operations in parallel
• k must be a power of 2
for fast modulo computation.
• Shared uint counters ngets, nputs
initialized to 0.
• Use fetch&incr( &nputs, 1) % k to
determine subqueue for next insert
• Use fetch&incr( &ngets, 1) % k to
determine subqueue for next extract
• Each subqueue is protected by a
fair lock.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

FetchAndIncr Instruction

A
boolean FetchAndIncr ( int *target, int k )
{
int old = *target;
*target = old + k;
return old;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Fair lock with FetchAndIncr

A

Acquire:
myticket = FetchAndIncr( &ticket, 1 );
while (myticket != active) ; // busy waiting
Release:
Fetch&Incr( &active, 1 );
(or: active ++; if store is atomic)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

LoadLinked address, register

A

records the version number of the value read

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

StoreConditional register, address

A

l will only succeed if no other operations were executed on
the accessed memory location since my last LoadLinked
instruction to address,
(cf. a svn commit)
l and set the register operand of Store-conditional to 0,
otherwise.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Mutual Exclusion using LL/SC

A
do {
register = 0;
    while ( register == 0) {
        dummy = LoadLinked ( &lock );
        if (dummy == 0) { // read a 0 – found unlocked
            register = 1;
            register = StoreConditional ( register, &lock ); }
            // if register is 0, StoreConditional failed, retry…
        }
      // … critical section
     lock = 0; // ordinary store
      // … remainder section
} while ( TRUE);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Mutual Exclusion using CAS

A
register = 1;
CAS ( &lock, 0, register );
while (register != 0)
     CAS ( &lock, 0, register );
// … … critical section
lock = 0;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Atomic Counter Increment with CAS

A
do {
    oldval = counter;
    newval = oldval + 1;
    CAS ( &counter, oldval, &newval );
} while (newval != oldval );
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The ABA Problem with Compare&Swap

A

ABA-Problem:
CAS cannot detect if a memory location has changed value
from a value A to a value B and then back to A again.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Doubly Linked List - How to atomically update both prev and next pointers?

A

Requires DCAS (double compare-and-swap)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

transactional memory

A

atomic {

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly