-1

Does signal() and wait() do in a semaphore algorithm? I know that one of them does S++ and the other S-- but I am not sure which one does which. I have checked out the signal algorithm and it seems to show that signal brings the counter down to 0.

Some programmer dude
  • 380,411
  • 33
  • 383
  • 585
  • Possible duplicate of [What is a semaphore?](https://stackoverflow.com/questions/34519/what-is-a-semaphore) – João Neto Feb 05 '19 at 11:58

1 Answers1

0

Conditional Variables are the ones with signal and wait.

A Conditional variable is used when you want a thread to wait until a certain condition is met.

while(!canProceed) { cond.wait(); }

When another thread wants to unblock these blocked threads, it simply calls signal (to unblock one) or broadcast (to unblock all).

canProceed = true
cond.broadcast()

Semaphores are simply generalizations of a mutex. While a mutex allows for one thread inside a given critical section, semaphores allow for N threads inside.

Threads initially wait to enter a critical section; after they're done they post (at least using the pthreads API).

semaphore.wait();
do_stuff();
semaphore.post();
João Neto
  • 1,622
  • 14
  • 28