Concurrency Flashcards

1
Q

Bit per critical section

A
  • for each critical session keep a variable to indicated whether a process is present
  • set it to 1 on entry, 0 on exit
  • test if bit=0 before we enter

issues:
▪ Testing at 0 and setting equal to 1 is not an atomic operation
→ process can be interrupted between testing and setting the bit
▪ if CS is occupied, then constant checking is required → busy waiting

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

List the different versions of Dekker’s algorithm and why they wouldn’t work

A

1) global variable ‘turn’ to indicate which process may use CS next
-> initialization will favor one process

2) Keep variable for each process and check whether the other process has the intention to enter
-> if interrupted after while loop: no mutual exclusion

3) = 2nd attempt + switching assignment and while lines
-> both processes flag at same time = stuck in while loop => deadlock

4) 3rd attempt + pause
-> waiting time is not bounded

Final Solution:
Single variable ‘turn’ to indicate which process will be courteous when in conflict.

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

What are the overall properties of Dekker’s algorithm?

A
  • Busy waiting occurs
  • Priority for process that entered the critical section least recently
  • Not trivial to generalize to n processes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Peterson’s Algorithm?

A
  • Announce desire to enter the CS
  • Set the turn to the other process
  • Verify whether P1 does not have intention or is in the CS
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How is Peterson’s Algorithm altered for n processes

A
  • Assume each process crosses n-1 phases before reaching the CS
  • use variables:
  • Flag[i] = phase of Pi
  • Turn[j]: which was the last process in phase j
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the characteristics of the hardware-base solutions?

A
  • prohibit interrupts during critical section
    -> disadvantageous for large critical sections
  • machine instruction support (spinlock)
    ▪ Test-and-set: bit per critical section
    ▪ Exchange: bolt=1 and for each process key=0, exchange from (key, bolt) to key=1
    ▪ Cons: busy waiting, no guarantees against starvation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Semaphore?

A

It is hardware-base solution introduced by Dijkstra.

  • wait-function:
    counter - 1 -> counter < 0? -> block process

-signal function:
counter + 1 -> counter < 0? -> oldest process unblocked

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

What is the Producers/Consumers Problem?

A
  • One or more processes produce data and write it to a buffer
  • One process access this data by reading it from the buffer

Challenges:
- Can only take something if it’s there
- may take it only once
- each produced item must have a new place

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

What is a binary semaphore?

A

◦ Counter (count) only accepts 0 or 1 as a value
▪ waitB(s): check if counter is 1, if so we lower it, otherwise we block it
▪ signalB(s): if no processes are blocked, then counter to one, otherwise unblock one process (oldest)
◦ Binary semaphores as powerful as counting semaphores

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

How do you get mutual exclusion with a semaphore?

A

◦ Semaphore per CS
▪ Initializing semaphore with one
▪ Entering Critical Section → wait(s)
▪ Exit CS → signal(s)
◦ wait(s) and signal(s) operations cannot be interrupted or occur simultaneously by different processes

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

What is the Readers/Writers problem?

A

◦ A number of readers want to read data (e.g. catalog), but the data can be modified by writers
◦ Readers
▪ Simultaneous access is allowed
▪ No writers allowed
◦ Writers
▪ A maximum of one writer is always active
▪ No readers may be active

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

Look at the Readers/Writers problem through Semaphores

A

◦ How many readers are active?
▪ r.count: variable the number of readers
▪ semaphore x enforcing mutual exclusion for r.count
◦ Stop writers when readers are active
▪ wsem: prevents writers as long as there are readers, if r.count decreases to zero then signal(wsem)
◦ Stop readers when writer is active
▪ wsem: if r.count to one then wait(wsem)

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