Semaphores Flashcards

(24 cards)

1
Q

⭐️ Give the definition:
An object with an integer value that we can manipulate with 2 routines

A

Semaphore

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

⭐️ What 2 routines can be used to manipulate a semaphore?

A

sem_wait & sem_post

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

⭐️ The motivation for semaphores is to block a processes execution until som condition is satisfied, so that we avoid…

A

busy waiting

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

⭐️ What routine for manipulation of a semaphore is described below?
Decrements sem value by 1. Waits if value of sem is < 0

A

wait

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

⭐️ What routine for manipulation of a semaphore is described below?
Increments sem value by 1. Then wakes up a single waiter if one exists.

A

post

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

⭐️ What routine for manipulation of a semaphore is described below?
Determines a semaphores behavior - the value of the semaphore when negative = number of waiting threads

A

initialization

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

⭐️ The negative value of a semaphore =

A

The number of waiting threads

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

Give the definition:
Binary semaphore

A

Lock

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

Which two operations can be used in combination with sem_init() with semaphores to solve the concurrency problem of ordering?

A

thr_join() & thr_exit()

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

Does the semaphore variable below represent the producer or the consumer in the p/c problem?
sem_t empty;

A

producer

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

Does the semaphore variable below represent the producer or the consumer in the p/c problem?
sem_t full;

A

consumer

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

What value is the sem_t value initialized to for the producer value, empty, in the p/c problem?

A

MAX

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

What value is the sem_t value initialized to for the consumer value, full, in the p/c problem?

A

0

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

When using semaphores in the p/c problem, the mutex locks are put just around the critical section to ensure that what state doesn’t occur?

A

Deadlock state - Avoids circular wait

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

⭐️ Give the definition:
A set of threads are said to be in this state when every thread in the set is waiting for an event that can be caused only by another thread in the set.

A

Deadlock state

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

⭐️ Which condition for a deadlock state is described below?
Threads claim exclusive control of resources that require e.g. a thread grabs a lock

A

Mutual exclusion

17
Q

⭐️ Which condition for a deadlock state is described below?
Threads hold resources allocated to them while waiting for additional resources

A

Hold-and-wait

18
Q

⭐️ Which condition for a deadlock state is described below?
Resources cannot be forcibly removed from threads that are holding them

A

No preemption

19
Q

⭐️ Which condition for a deadlock state is described below?
There exists a circular chain of threads such that each holds one/more resources that are being requested by the next thread in the chain.

A

Circular wait

20
Q

⭐️ A counting semaphore is initialized to 5. What does this imply?
1. Only 5 threads can exist in the system
2. Up to 5 threads can access the critical section simultaneously
3. The semaphore can only be locked 5 times before failing
4. It is equivalent to 5 binary semaphores

21
Q

⭐️ What happens if a thread executes wait() on a semaphore with a value of 0?
1. The thread terminates immediately
2. The thread blocks until another thread calls signal()
3. The OS throws an exception
4. The semaphore value becomes 1

22
Q

⭐️ In the producer-consumer problem with only semaphores, how many semaphores are typically used?
1. 1
2. 2
3. 3
4. 4

A
  1. In order to guarantee mutex when accessing the shared buffer, a binary semaphore is needed in addition to empty & full semaphores
23
Q

⭐️ What is the key difference between a semaphore & a condition variable?
1. Semaphores are faster
2. Semaphores maintain state (the counter), while CVs do not
3. Conditional variables can ensure mutual exclusion
4. Semaphores needs to be used with mutexes

24
Q

⭐️ Two semaphores are typically used to implement a correct solution for the
producer-consumer problem (T/F)