Re: How to wait for multiple threads simultaneously?

David Schwartz <davids@xxxxxxxxxxxxx> writes:
On Feb 13, 1:51 am, Rainer Weikusat <rweiku...@xxxxxxxxxxx> wrote:

You can then spin on that condition variable.

To 'spin' on some lock would mean to busy-wait until it is free, eg

while (try_to_take(&lock) == FAILED);

Right, but a condition variable is not a lock. To 'spin' on a
condition variable means to block on it until the predicate occurs,

A 'spin lock' is one which does not involve blocking, but
busy-waiting. 'Condition variables' are something threads can block
on, hence, they don't "spin" on them. That blocking on pthread cond
vars may result in spurious wakeups is an accidental property of them.
The normal use is till to block on the condition variable until it is

The verb itself describes a continous, fast activity. IMO, it's just
potentially confusing to use it for something completely different
(occasional retesting of a condition).


Relevant Pages

  • Re: How to wait for multiple threads simultaneously?
    ... because a "spin lock" is special. ... If they loop until something happens, ... Even if condition variables guaranteed no spurious wakeups, ... "The pthread_spin_lock() function shall lock the spin lock referenced ...
  • Re: Why I believe in static analysis
    ... >> build your own lock object since you don't quite have sufficient ... Yes, macros would make thing better, and the Java ...
  • Re: Promises, futures -- implementation suggestions?
    ... has finished its computations" than using a lock? ... release mutex & return value (the value ... SBCL exposes condition variables. ...
  • Re: Linking without -lpthread doesnt fail??
    ... both mutexes and condition variables. ... You should be able to lock and unlock mutexes -- there's no chance of lock contention because there's only one thread. ... But correct program logic makes that irrelevant because there's no way a predicate could fail to be satisfied (i.e., no reason to ever wait). ... Timed wait is a special case, though, because there is a common idiom of treating ETIMEDOUT as the predicate condition, and that can be satisfied without another thread. ...
  • Re: Thread Race condition here?
    ... A semaphore maintains a counter internally, so use that if you can. ... If possible, turn lLimresActivect into a ... condition variables allow you to do this sort of thing: ... // Here condition is true and we have the lock, ...