Re: How to wait for multiple threads simultaneously?
- From: David Schwartz <davids@xxxxxxxxxxxxx>
- Date: Sun, 17 Feb 2008 13:47:24 -0800 (PST)
On Feb 17, 11:12 am, Rainer Weikusat <rweiku...@xxxxxxxxxxx> wrote:
This is presumably an omission, because a 'POSIX spin lock' would not
be anyhow different from an ordinary mutex, then, and completely
redundant.
It is not *required* to be different. However, if it's redundant, then
so are condition variables, because you can always just release the
mutex, yield, and re-acquire the mutex. POSIX does not require that to
be different from phtread_cond_wait either.
A 'spin lock' is a synchronisation primitive intended for locks which
are only held for very short times on a multiprocessor, specifically,
for times which are short enough that the overhead of marking the
process/ thread as no longer runnable, switching to a different
'execution context', marking the process as runnable again and
switching back to it would be excessive when compared with the time
the lock is actually held. Instead of going to sleep, the process/
thread 'spins' in a loop, trying to reacquire the lock until that
succeeds. Combinations of both approaches exist, too, eg mutexes on
which a thread spins for a short time and if it couldn't acquire the
lock during this time, goes to sleep to avoid tying up a processor for
no particular reason.
Right, that is when you use a spin lock. But then it is the
implementation's decision what the right thing to do in that
circumstance is. For example, if there's only a single CPU, the
implementation may justifiably refuse to spin. The program can't know
whether spinning is appropriate, only that it believes circumstances
are such that it might be.
The point is, we call it "spinning" because it's a tight loop that
might consume CPU, not because it must busy wait. The implementation
need not busy wait if it knows that's not appropriate.
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
- 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
- Re: How to wait for multiple threads simultaneously?
- From: David Schwartz
- 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: Re: add-on/ or app to help dyslexi children learn to read
- 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
|