Lecture 6: Synchronization Flashcards

1
Q

define race condition

A

several process access and manipulate the same data at the same time so that the outcome of execution is depends on the order of process executioln

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

what is critical section

A
  • process may be changing common variables, updating table, writing file, …
  • critical section problem design protocol to solve race condition
  • each process need to ask permission to enter critical section in entry section, follow by exit section and remaining section
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

define mutual exclusive

A

if a process,P1 is executing in its critical section, no other process can enter its critical section

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

define bound waiting

A

bound must exist when process are allowed to enter their critical section
- after request is made
- before request is granted

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

Peterson’s Solution

A
  • used to restrict two process to alternate execute between critical section and remaining section
  • assume LOAD and STORE cannot be interrupt
  • sharing 2 variables: int turn and boolean flag[2]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

int turn variables

A

determine whose turn to enter the critical section

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

boolean flag

A

determine if a process is ready to enter the critical section

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

critical section problem’s solution requirement

A
  • bound waiting requirement
  • progress requirement
  • mutual exclusive
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

other solution for critical section problem

A
  • lock
  • test memory word and set value: test_and_set()
  • swap content of two memory word: compare_and_swap()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

how Mutex Lock work

A
  • process acquire a lock before entering critical section
  • then release the lock after exit the critical section
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is semaphore S

A

an integer variable that can only accessed through wait() and signal()

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

counting semaphore

A
  • initialized to number of resources available
  • process perform a wait() in order to use the resource
  • process perform a signal when release the resource
  • all resources are being used when semaphore count = 0
  • process will be blocked until semaphore count >0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

3 classical problems of synchronization

A
  • bounded-buffer problem
  • reader and writer problem
  • dining’s philosophers problem
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

problem with dining philosophers

A
  • possibly create deadlock
  • all philosophers hungry at the same time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

how to prevent deadlock in dining philosophers problem

A
  • allow at most n-1 philosophers
  • allow pick up when both chopstick are available
  • asymmetric solution: odd number pick left first and even number pick right first
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

define progress

A

if no process in critical section, the selection of the next process cannot be postponed indefinitely

17
Q

disadvantages of reader and writer problem

A
  • allow multiple reader read at the same time
  • only one writer can access the data at one time