Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [semaphore]

The tag has no usage guidance.

0
votes
1answer
49 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
1answer
111 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 ...
3
votes
1answer
192 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 ...
12
votes
1answer
867 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
2answers
1k 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() { ...
5
votes
2answers
1k 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 ...