Semaphores A. synchronize critical resources to prevent deadlock B. synchronize critical resources to prevent contention C. are used to do I/O D. are used for memory management E. None of the above

[amp_mcq option1=”synchronize critical resources to prevent deadlock” option2=”synchronize critical resources to prevent contention” option3=”are used to do I/O” option4=”are used for memory management E. None of the above” correct=”option1″]

The correct answer is: A. Semaphores synchronize critical resources to prevent deadlock.

A semaphore is a synchronization primitive that is used to control access to a shared resource. It is a variable that can take on two values: 0 or 1. When the semaphore is 0, no process can access the resource. When the semaphore is 1, one process can access the resource.

Semaphores are used to prevent deadlock. Deadlock is a situation in which two or more processes are waiting for each other to release a resource that they need. This can happen if each process is holding a resource that the other process needs.

To prevent deadlock, semaphores can be used to ensure that only one process can access a resource at a time. This can be done by using a semaphore to control access to the resource. The semaphore is initialized to 1, and when a process needs to access the resource, it decrements the semaphore. When the process is finished with the resource, it increments the semaphore.

If two processes are trying to access the resource at the same time, only one of them will be able to access it. The other process will have to wait until the first process is finished. This prevents deadlock from occurring.

Options B, C, and D are incorrect because semaphores are not used for those purposes. Semaphores are not used to do I/O, and they are not used for memory management.