Sync w/o Busy Waiting Flashcards

1
Q

Race Condition

A

If final program result depends on the execution/scheduling sequence

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

Critical Section

A

Program region that has to access shared data in a synchronized way or else race condition will occur

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

Mutual Exclusion

A

Preventing two or more processes from being inside a critical section simultaneously

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

lock() code

A

p = 0 #shared between processes

void lock( int *p ) {
while( test_and_set(&p) == 1 );
}

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

Semaphore

A
  • has counter to indicate the number of available resources
  • has queue holding processes waiting for the semaphore
  • has a busy-waiting lock ( based on test_and_set() )
  • has two functions: DOWN() and UP()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

unlock() code

A

p = 0 #shared between processes

void unlock( int *p ) {
*p = 0 }

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

test_and_set() code

A

int test_and_set( int *p ) {
int t= *p
*p = 0
return t

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

down() code

A

semaphore S
down(S) {
if( S.num > 0 ) S.num –;
else { put current process in wait queue; }
}

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

up() code

A

semaphore S
up(S) {
if( any processes in wait queue) { pop process from wait queue; resume process; }
else { S.num ++; }
}

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

Binary Semaphore

A

Semaphore whose counter value is restricted to 0 or 1

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

Monitor

A

Programming language construct that supports controlled access to shared data. Has mutex lock and queue. Encapsulates:
- shared data
- shared data procedures
- synchronization between concurrent processes

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

Monitor Java Method

A
  • uses “Synchronized” label to implement Monitor object
  • inserts lock() and unlock() at entry and exit of each procedure
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

CV

A

Condition Variable. Used to show events like availability of shared variables. Three operations:
- wait(c, lock): puts process in wait queue and unlock
- signal(c): move process from CV queue to monitor queue
- broadcast(c): wake all processes from CV queue to monitor queue

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

CV vs Semaphore

A
  • semaphore has counter and wait queue
  • CV only has wait queue
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Look at semaphore use examples

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