Re: How to wait for multiple threads simultaneously?
- From: David Schwartz <davids@xxxxxxxxxxxxx>
- Date: Wed, 13 Feb 2008 12:48:49 -0800 (PST)
On Feb 13, 3:52 am, Rainer Weikusat <rweiku...@xxxxxxxxxxx> wrote:
A 'spin lock' is one which does not involve blocking, but
busy-waiting.
Right, but this is not because of the general meaning of "spin" but
because a "spin lock" is special.
'Condition variables' are something threads can block
on, hence, they don't "spin" on them.
If they loop until something happens, they are spinning.
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
signaled.
That's not the only reason you spin. Another thread have consumed the
predicate. Even if condition variables guaranteed no spurious wakeups,
many applications would still need to spin on th predicate.
To "spin" is simply to loop tightly, that is, without running complex
functional code in each iteration. The purpose of the loop is simply
to exit at the right time.
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).
And yet using it the way I am using it seems to be common. For example
POSIX says:
"The pthread_spin_lock() function shall lock the spin lock referenced
by lock. The calling thread shall acquire the lock if it is not held
by another thread. Otherwise, the thread shall spin (that is, shall
not return from the pthread_spin_lock() call) until the lock becomes
available."
So all POSIX means by "spin" is "not return".
DS
.
- Follow-Ups:
- Re: How to wait for multiple threads simultaneously?
- From: Rainer Weikusat
- Re: How to wait for multiple threads simultaneously?
- References:
- How to wait for multiple threads simultaneously?
- From: chjfth
- Re: How to wait for multiple threads simultaneously?
- From: David Schwartz
- Re: How to wait for multiple threads simultaneously?
- From: Rainer Weikusat
- Re: How to wait for multiple threads simultaneously?
- From: David Schwartz
- Re: How to wait for multiple threads simultaneously?
- From: Rainer Weikusat
- How to wait for multiple threads simultaneously?
- Prev by Date: Re: How to wait for multiple threads simultaneously?
- Next by Date: portable application
- Previous by thread: Re: How to wait for multiple threads simultaneously?
- Next by thread: Re: How to wait for multiple threads simultaneously?
- Index(es):
Relevant Pages
|