Which synchronization primitive is commonly used by threads to wait for a condition to become true and to signal other threads when it changes?

Get ready for your Fundamentals of Computing Test. Utilize flashcards and multiple-choice questions. Every question includes hints and explanations. Prepare effectively and ace your exam now!

Multiple Choice

Which synchronization primitive is commonly used by threads to wait for a condition to become true and to signal other threads when it changes?

Explanation:
Condition variables are the mechanism that lets threads wait for a specific condition to become true and lets other threads signal when that condition changes. The usual pattern is that a thread holds a mutex and checks a shared predicate; if the predicate isn’t true yet, it waits on the condition variable. Waiting releases the mutex and blocks the thread until another thread signals the condition variable. When signaled, the waiting thread wakes up, reacquires the mutex, and rechecks the condition (usually in a loop) to guard against spurious wakeups. This combination ensures that threads don’t miss changes to the condition and that access to the shared state stays synchronized. Locks by themselves only enforce mutual exclusion and don’t provide a built-in way to wait for or signal a particular condition. Semaphores can coordinate counts and resource access but aren’t tied to a specific boolean condition, making them less direct for signaling “the condition is now true.” Monitors offer a higher-level construct that packages mutex behavior with condition queues, but the specific primitive designed for waiting for a condition and signaling its change is the condition variable.

Condition variables are the mechanism that lets threads wait for a specific condition to become true and lets other threads signal when that condition changes. The usual pattern is that a thread holds a mutex and checks a shared predicate; if the predicate isn’t true yet, it waits on the condition variable. Waiting releases the mutex and blocks the thread until another thread signals the condition variable. When signaled, the waiting thread wakes up, reacquires the mutex, and rechecks the condition (usually in a loop) to guard against spurious wakeups. This combination ensures that threads don’t miss changes to the condition and that access to the shared state stays synchronized.

Locks by themselves only enforce mutual exclusion and don’t provide a built-in way to wait for or signal a particular condition. Semaphores can coordinate counts and resource access but aren’t tied to a specific boolean condition, making them less direct for signaling “the condition is now true.” Monitors offer a higher-level construct that packages mutex behavior with condition queues, but the specific primitive designed for waiting for a condition and signaling its change is the condition variable.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy