Boost logo

Boost Users :

Subject: Re: [Boost-users] Q: N00b spinlock
From: strasser_at_[hidden]
Date: 2010-01-21 15:10:56


Zitat von Tim Blechmann <tim_at_[hidden]>:

> as rule of thumb, i am using spinlocks in the following cases:
> - locks are acquired very rarely
> - critical region is very short (a instructions)
> - the number of threads to be synchronized is lower than the number of
> cpu cores
> - the synchronized threads have a similar (possibly real-time) priority

a set of condition also known as "never" ;-)
if the lock is acquired "very rarely" what is the advantage of a
spinlock anyway?

>
> btw, using yield() inside a spinlock may cause unwanted behavior, since
> it preempts the calling thread, but the scheduler keeps it as `ready'
> instead of `blocked'. so it may wake up, before it can acquire the
> mutex, burning cpu cycles.

yes, I guess that´s what I was observing, switching between the
yield()ing threads instead of continueing with the thread that
acquired the lock.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net