Reading: Concurrency. Read pages 1-9 of “The Little Book of Semaphores” (http://
ID: 3715453 • Letter: R
Question
Reading: Concurrency. Read pages 1-9 of “The Little Book of Semaphores” (http://greenteapress.com/wp/semaphores/). Answer the following questions by editing file hw13.txt.
1) Suppose we cannot tell, by looking at the source code for a program, which of two events will happen first. Then the two events are a) concurrent, or b) sequential?
2) What would you call an operation that can’t be interrupted? a) shared, b) synchronizable, or c) atomic?
3) Suppose a semaphore is created with value 0, then two threads call wait() on the semaphore, so that the two threads get blocked, and the semaphore value is -2. If another thread now calls signal() on the semaphore, what happens? a) one of the blocked threads is unblocked, or b) nothing, because after the signal the semaphore is still negative.
4) Suppose a thread is blocked on a semaphore, and another thread then performs a signal() operation on the semaphore. What happens immediately afterward? a) the thread that performed the signal continues execution, b) the thread that was blocked will unlock and begin executing immediately, c) some other thread begins execution, or d) the programmer doesn’t know which of a,b,c might happen.
5) Semaphores can be used a) in place of locks, b) in place of condition variables, or c) in place of both locks and condition variables.
Explanation / Answer
Answer is below with correct options choose in bold characters.
1) Suppose we cannot tell, by looking at the source code for a program, which of two events will happen first. Then the two events are concurrent.
2) What would you call an operation that can’t be interrupted?
=> An operation that cannot be interrupted is to be atomic.
3) Suppose a semaphore is created with value 0, then two threads call wait() on the semaphore, so that the two threads get blocked, and the semaphore value is -2. If another thread now calls signal() on the semaphore, what happens?
=> nothing, because after the signal the semaphore is still negative.
4) Suppose a thread is blocked on a semaphore, and another thread then performs a signal() operation on the semaphore. What happens immediately afterward?
=> the thread that was blocked will unlock and begin executing immediately
5) Semaphores can be used in place of both locks and condition variables.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.