Question

In: Computer Science

semaphores

onsider the following definition of semaphores:
void semWait(s)
{
if (s.count > 0) {
s.count--;
}
else {
place this process in s.queue;
block;
}
}
void semSignal (s)
{
if (there is at least one process blocked on
semaphore s) {
remove a process P from s.queue;
place process P on ready list;
}
else
s.count++;
}
Compare this set of definitions with that of Figure 5.3. Note one difference: With the preceding definition, a semaphore can never take on a negative value. Is there any difference in the effect of the two sets of definitions when used in programs? That is, could you substitute one set for the other without altering the meaning of the program?

Solutions

Expert Solution

The two are equivalent. In the definition of Figure, when the value of the semaphore is negative, its value tells you how many processes are waiting. With the definition of this problem, you don't have that information readily available. However, the two versions function the same.  you don't have that information readily available. However, the two versions function the same.

 

 


 you don't have that information readily available. However, the two versions function the same.

Related Solutions

general semaphores
It should be possible to implement general semaphores using binary semaphores. We can use the operations semWaitB and semSignalB and two binary semaphores, delay and mutex. Consider the following:void semWait(semaphore s){semWaitB(mutex);s--;if (s < 0) {semSignalB(mutex);semWaitB(delay);}else SemsignalB(mutex);}void semSignal(semaphore s);{semWaitB(mutex);s++;if (s
What are Semaphores and Mutex? What are they used for?
What are Semaphores and Mutex? What are they used for?
The project will study the coordination of multiple threads using semaphores. The design should consist of...
The project will study the coordination of multiple threads using semaphores. The design should consist of two things: (1) a list of every semaphore, its purpose, and its initial value, and (2) pseudocode for each function. Code Your code should be nicely formatted with plenty of comments. The code should be easy to read, properly indented, employ good naming standards, good structure, and should correctly implement the design. Your code should match your pseudocode. Project Language/Platform This project must target...
Q3) Explain; how the synchronization mechanism (semaphores) can be used, to ensure a correct access to...
Q3) Explain; how the synchronization mechanism (semaphores) can be used, to ensure a correct access to exclusive resources.
Answer the following: a) What is a critical region? b) How can counting semaphores be used...
Answer the following: a) What is a critical region? b) How can counting semaphores be used to provide exclusive access to a critical region? c) Describe the operation (clearly, in English) of the semWait and semSignal actions of a counting semaphore.
can someome investigate my program that utilizes semaphores that can result in deadlock due to programming...
can someome investigate my program that utilizes semaphores that can result in deadlock due to programming errors and help in finding out if the solution meet all criteria for the critical section If yes, then comment code identifying the parts of code that do If no, could you help in fixing the code wherever given solution fails criteria in the code below #include <pthread.h> #include <semaphore.h> #include <stdio.h> #include <unistd.h> #define N 5 #define THINKING 2 #define HUNGRY 1 #define...
using 2 semaphores and 1 mutex: (solve in simple c++ language for linux terminal and add...
using 2 semaphores and 1 mutex: (solve in simple c++ language for linux terminal and add comments please) The barber shop has one barber (a thread), one barber chair, and n chairs for waiting customers (semaphore), if any, to sit on. If there are no customers (each customer is a thread) present, the barber sits down in the barber chair and falls asleep. When a customer arrives, he has to wake up the sleeping barber. If additional customers arrive while...
In C programming: Using mutexes, semaphores, and spinlocks, you can sequence memory operations to prevent race...
In C programming: Using mutexes, semaphores, and spinlocks, you can sequence memory operations to prevent race conditions. It might make some sense to just chuck spinlocks out the window and use mutexes. Explain why mutexes would tend to relieve you of some of the problems inherent in spinlocks. Explain a situation in which those benefits might not be worth your time and you’d go with the spinlock anyway.
Task 2 [10 pts] Implementing Synchronization of Chat Client Threads Using Semaphores In c language In...
Task 2 [10 pts] Implementing Synchronization of Chat Client Threads Using Semaphores In c language In this task, a character buffer should be created (e.g., char buf[500]) in the server which is shared among threads that are created to handle communication with clients. Specifically, when the server receives a message (a string) from a client, the server should (1) store the message in the buffer, (2) broadcast the message to all connected clients, and (3) clear the buffer. Make sure...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT