Questions tagged [semaphore]
The semaphore tag has no usage guidance.
17
questions
0
votes
1
answer
75
views
How to design a fifo coupon distribution system
I have an app written in java and using mysql as DB. I need to create a coupon distributed system where I have 100 coupons stored in DB and the first 100 customers who login should get those coupons. ...
0
votes
1
answer
96
views
Difference between outcome of using mutex/spinlock/semaphore in this deadlock situation?
I'm not sure if my answers to the following exercise is correct:
Suppose the program is run with two threads. Further suppose that the
following sequence of events occurs:
Time Thread 0 ...
3
votes
2
answers
2k
views
When should one utilize Atomic Operations?
I have never used atomic operations, and remain largely ignorant of how to utilize them. And yet, I often come across objects like this when peering into Qt's backend:
https://doc.qt.io/qt-6/...
-4
votes
3
answers
569
views
What is "it is possible for one process to lock a binary semaphore and for another to unlock it" useful for?
Here are some discussions about mutex (lock) and binary semaphore from two OS books.
Stalling's Operating Systems book says
A concept related to the binary semaphore is the mutex . A key ...
1
vote
2
answers
2k
views
Why is it that "the process that locks the mutex must be the one to unlock it "?
Here are some discussions about mutex (lock) and binary semaphore from two OS books.
Stalling's Operating Systems book says
A concept related to the binary semaphore is the mutex . A key ...
1
vote
1
answer
1k
views
Is there still busy waiting in the process-blocking implementation of a semaphore?
Operating System Concepts discusses two implementations of a semaphore, by busy waiting in Section 5.5 and by blocking the current process in Section 5.6:
Section 5.5
A semaphore S is an integer ...
-1
votes
1
answer
219
views
Why does "producers and consumers check availability before getting the mutex" avoid deadlock?
In Little Book of Semaphores:
4.1.6 Finite buffer producer-consumer solution
Finite buffer consumer solution
1 items.wait ()
2 mutex.wait ()
3 event = buffer .get ()
4 mutex. signal ()
5 spaces . ...
0
votes
1
answer
1k
views
Is a semaphore always initialized to the maximum value it can take?
According to Wikipedia:
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 ...
-1
votes
1
answer
126
views
is there difference between releasing two semaphores in the same or reverse order as they are acquired?
Generally, if two semaphores are acquired one after the other, is there difference between releasing them in the same order or the reverse order as they are acquired?
In the following solution to the ...
27
votes
5
answers
6k
views
Is "releases mutexes in reverse order" required to make this deadlock-prevention method work?
Operating System Concepts says
7.4.4 Circular Wait
The fourth and final condition for deadlocks is the circular-wait condition. One
way to ensure that this condition never holds is to impose a total ...
-2
votes
2
answers
1k
views
what would happen if you signal() before wait()?
A bakery shop has to provide a stream of muffins for customers. The muffins are made by a baker in the kitchen and placed on a conveyor belt. The conveyor belt carries the muffins to where the ...
-1
votes
1
answer
266
views
Is it better to initialize semaphores in shared memory or give them as command line arguments? (C++)
I am on a project for which I have to spawn many different processes, all in different executables, and there will be some shared memory segments and some semaphores to synchronize them. I use an "...
-1
votes
1
answer
2k
views
Is there a race condition for multiple threads on multiple cores trying to lock a global variable?
I understand in a single core system, multiple threads operate in sequence, scheduled by the OS. Hence it can't be possible to have a race condition since by definition they are taking turns locking a ...
4
votes
1
answer
350
views
Simple solution for calling a function only on one thread, queuing waiting calls?
Let’s assume there is a function EventHandler that is called on multiple threads at different points in time.
EventHandler has to call SomeOtherFunction, but these calls shall only happen on one ...
16
votes
1
answer
2k
views
Why is a semaphore called a semaphore?
It doesn't seem to me that a railway semaphore describes a semaphore better than any other generic signalling object, like a flag or a stoplight. Even something like a keyring (people take keys off ...
1
vote
2
answers
5k
views
How Semaphore Signal Works
I seem to have trouble understand the Semaphore implementation.
Q = Queue.
Wait(Process P) {
value = value - 1;
if (value < 0) {
add P to Q;
P->block();
}
}
Signal() ...
8
votes
2
answers
5k
views
Mutex vs Semaphore: How to implement them _not_ in terms of the other?
Recently I had to implement a Semaphore using a Mutex and a Conditional Variable (this combination is also known as a Monitor) for an exercise at the university:
the Semaphore's decrement operation ...