Semaphores Flashcards

1
Q

What is a semaphore?

A

A semaphore is a signal that indicates whether something can continue or must wait.

Semaphores consist of a queue and an integer value (sem).

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

What are the two semaphore methods?

A

semWait:

If sem > 0

Then sem = sem - 1

Else make the process wait

semSignal:

If there is a process waiting in the queue for this semaphore

Then allow the process to resume processing

Else sem = sem + 1

semWait and semSignal should be implemented as atomic actions.

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

(3 answers)

What are the different types of semaphore?

A
  • Binary
    • Mutual exclusive access to a single shared resource
  • Counting
    • Protect access to multiple instances of a single shared resource
  • Blocking
    • Synchronise two processes (a producer and a consumer)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

(4 answers)

What are binary semaphores and how do they work?

A
  • Several processes share one semaphore
  • Semaphore is initialised to 1 (available)
  • When a process enters the critical region, the semaphore value is changed to 0
  • When the process leaves the critical region, a waiting process enters, or the semaphore value is changed back to 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

(4 answers)

What are counting semaphores and how do they work?

A
  • Several processes share multiple semaphores (or permits)
  • Semaphore is initialised to the number of instances of the resource available
  • When a process enters the critical region, the semaphore value is decreased by 1
  • When the process leaves the critical region, a waiting process enters or the semaphore value is increased by 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

(5 answers)

What are blocking semaphores and how do they work?

A
  • Consumer and producer processes share one semaphore
  • Semaphore is initialised to 0 (blocked)
  • The consumer calls semWait to check whether data has been written
  • When the producer finishes writing, it calls semSignal and the semaphore is changed to 1
  • The consumer is then allowed to enter the critical region
How well did you know this?
1
Not at all
2
3
4
5
Perfectly