← BYTES
Unix IPC·Starter·Ref: 15.1.63

What is a condition variable used for?

Have a question about this video? Mention reference 15.1.63 when you contact us.

   Thread A:  wait(cond)   -->  (sleeps, using no CPU)
   Thread B:  ... does some work ...
   Thread B:  signal(cond) -->  wakes Thread A back up
a.Storing a boolean true/false value permanently on disk
b.Declaring a variable's data type at compile time
c.Letting a thread efficiently wait (sleep) until some other thread signals that a specific condition it cares about has become true, instead of repeatedly checking in a loop
d.Encrypting data shared between two threads
A condition variable lets a thread block efficiently until notified that something it's waiting for has happened (e.g. 'the queue is no longer empty'), rather than wastefully checking that condition over and over -- it's always used together with a mutex, covered in later questions.

Find this on YouTube & Instagram

Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:

#BYTES#BYTES15163#UnixIPC