A binary semaphore is logically just like a mutex. There are two basic sorts of semaphores: binary semaphores, which never take on values other than zero or one, and counting semaphores, which can take on arbitrary nonnegative values. sem_trywait(3R) is a conditional form of the P operation: if the calling thread cannot decrement the value of the semaphore without waiting, the call returns immediately with a nonzero value. Sem_wait(3R) and sem_post(3R) correspond to Dijkstra's P and V operations. This is discussed in one of Dijkstra's technical notes, EWD 74. V stands for verhogen, which means increase. However, in the interest of true scholarship: P stands for prolagen, a made-up word derived from proberen te verlagen, which means try to decrease. The mnemonic significance of P and V is lost on most of the world, as Dijkstra is Dutch. If two V operations are performed simultaneously on the same semaphore, the net effect should be that the semaphore's new value is two greater than it was. In both P and V operations, the arithmetic must take place without interference. In the P operation, the semaphore's value must be positive just before it is decremented (resulting in a value that is guaranteed to be nonnegative and one less than what it was before it was decremented). It is crucial that these operations take place atomically-they cannot be subdivided into pieces between which other actions on the semaphore can take place. When it is finished, the thread performs a V operation, which changes the semaphore's value by adding one to it. The semantics of the operation are such that the thread must wait until the semaphore's value is positive, then change the semaphore's value by subtracting one from it. A thread waits for permission to proceed and then signals that it has proceeded by performing a P operation on the semaphore. In the computer version, a semaphore appears to be a simple integer. A train that is leaving this section of track must again change the state of the semaphore to allow another train to enter. When the train enters the track, the semaphore changes state to prevent other trains from entering the track. A train must wait before entering the single track until the semaphore is in a state that permits travel. Dijkstra's model was the operation of railroads: consider a stretch of railroad in which there is a single track over which only one train at a time is allowed. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.Semaphores are a programming construct designed by E. Two binary semaphores Xb and Yb are used to implement the semaphore operations P(s) and V(s) as follows:P(s) : Pb(Xb) s = s - 1 if (s < 0) else Vb(Xb) V(s) : Pb(Xb) s = s + 1 if (s <= 0) Vb(Yb) Vb(Xb) The initial values of Xb and Yb are respectivelya)0 and 0b)0 and 1c)1 and 0d)1 and 1Correct answer is option 'C'. The P and V operations on counting semaphores, where s is a counting semaphore, are defined as follows:P(s) : s = s - 1 if (s < 0) then wait V(s) : s = s + 1 if (s <= 0) then wakeup a process waiting on s Assume that Pb and Vb the wait and signal operations on binary semaphores are provided.
0 Comments
Leave a Reply. |