Prepare for the 241 Computer Science Certification Exam with comprehensive flashcards and multiple choice questions. Enhance knowledge with explanations and hints to excel in your test journey!

Multiple Choice

What is a semaphore and how is it used for process synchronization?

A semaphore is a synchronization primitive used to control access to shared resources and to coordinate the order in which processes run. It can be binary, acting like a lock with a value of 0 or 1 to enforce mutual exclusion, or counting, which tracks how many instances of a resource are available. The mechanism revolves around two operations: wait (often called P or down) and signal (often called V or up). When a process performs a wait, it attempts to decrease the semaphore’s value; if the value would go negative, the process blocks until another process signals. When a process performs a signal, it increases the value and, if any processes are waiting, wakes one of them. This lets multiple processes coordinate access to a shared resource without two processes entering the critical section at the same time (in the binary case) and allows up to a limit of concurrent accesses (in the counting case). Semaphores are about synchronization and resource management, not about exchanging messages, managing memory allocation, or measuring CPU usage.

A semaphore is a synchronization primitive used to control access to shared resources and to coordinate the order in which processes run. It can be binary, acting like a lock with a value of 0 or 1 to enforce mutual exclusion, or counting, which tracks how many instances of a resource are available. The mechanism revolves around two operations: wait (often called P or down) and signal (often called V or up). When a process performs a wait, it attempts to decrease the semaphore’s value; if the value would go negative, the process blocks until another process signals. When a process performs a signal, it increases the value and, if any processes are waiting, wakes one of them. This lets multiple processes coordinate access to a shared resource without two processes entering the critical section at the same time (in the binary case) and allows up to a limit of concurrent accesses (in the counting case). Semaphores are about synchronization and resource management, not about exchanging messages, managing memory allocation, or measuring CPU usage.