(2) a question about Operating Systems: a) Explain what is meant by a semaphore
ID: 662339 • Letter: #
Question
(2) a question about Operating Systems:
a) Explain what is meant by a semaphore in the context of concurrent systems. b) Describe how the Java programming language keywords synchronized, wait, and notify provide support for thread synchronization. c) A thread Barrier is a synchronization object which allows a fixed number of threads to all wait for each other by asking that each thread calls a method waitForOtherThreads on the barrier object when they reach a 'barrier' point in their execution. Only when all of the threads have called this method can any of the threads proceed until the next barrier point in their code. Listed below is a Java class Barrier which implements this synchronization object. Write a pseudo-code class for a Barrier object which uses Semaphore objects rather than the Java synchronization primitives.Explanation / Answer
1.
In computer science, particularly in operating systems, a semaphore is a variable or abstract data type that is used for controlling access, by multiple processes, to a common resource in a parallel programming or a multi user environment.
A useful way to think of a semaphore is as a record of how many units of a particular resource are available, coupled with operations to safely (i.e., without race conditions) adjust that record as units are required or become free, and, if necessary, wait until a unit of the resource becomes available. Semaphores are a useful tool in the prevention of race conditions; however, their use is by no means a guarantee that a program is free from these problems. Semaphores which allow an arbitrary resource count are called counting semaphores, while semaphores which are restricted to the values 0 and 1 (or locked/unlocked, unavailable/available) are called binary semaphores
2. An object for which access is to be coordinated is accessed through the use of synchronized methods. These methods are declared with the synchronized keyword. Only one synchronized method can be invoked for an object at a given point in time. This keeps synchronized methods in multiple threads from conflicting with each other.
We can call the wait() method of any Java object, which suspends the current thread. The thread is said to be "waiting on" the given object.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.