Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COthat is why a condition variable is always associated to... a condition. you use a mutex to ensure coherent access to that condition, and you check for it in a while loop. (to account for spurious wake ups, and concurrently mutex acquiring threads that may have changed the condition after the notify.)
      singulars
    2. COThe problem I'm going for is an event that occurs once. Think of a thread that dispatches other threads. For example you want to continue execution of the dispacher only if the dispached thread has actually run for some time. For this I use two semaphores: The dispatcher creates the thread and posts a 'dispatch' semaphore. The dispatched thread waits for it. After setting the dispatch semaphore the dispatcher waits for a worker semaphore to be posted by the worker. This mechanism fails using the events above because in most cases the worker will miss the dispatcher's signal and block forever.
      singulars
    3. COWell yes of course. that is why condition variables do not focus on the event, but on the condition. your condition is a variable, for example a bool that flags 'go for it !' that your worker will read. If it is false, it waits on the condition_variable until a signal, it wakes up, checks the 'go for it flag'. If the flag is true it means the signal was sent before the worker arrived at that point so it doesn't even wait. the mutex is here to access this flag with the correct memory barriers.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload