Boost logo

Boost :

Subject: Re: [boost] [thread] shared_spinlock_t idea or faster shared_lock
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2014-05-02 06:31:38


2014-05-02 13:26 GMT+04:00 Giovanni Piero Deretta <gpderetta_at_[hidden]>:

> On Fri, May 2, 2014 at 6:37 AM, Antony Polukhin <antoshkka_at_[hidden]>
> wrote:
> > Hi,
> >
> > This is just a refining of idea that was once implemented and worked
> well.
> > The idea was to make shared spin lock. Here is some pseudo-code:
> >
> > When all the *_wait() and writer_*() functions do nothing we get a shared
> > spinlock.
> >
>
> [snip]
>
> > Now if we add helper mutex and make all the *_wait() functions to lock
> and
> > unlock mutex; writer_start() - lock the mutex; writer finished() - unlock
> > the mutex... we get a simplified shared_mutex that is faster (in theory)
> > than current implementation.
> >
> > Is there an interest in such shared_spinlock_t? Any comments,
> suggestions?
> >
>
> Not sure, you generally want to use a spinlock when you expect
> contention to be very low. If you expect contention to be high enough
> that a r/w lock could be a win, you probably do not want to spin
> anyway.
>

Read/write locks are not cheap (at least in Boost.Thread because of
interruptions). For cases when there is is high read contention and
critical section is *very* small shared spinlocks could show a better
performance.

-- 
Best regards,
Antony Polukhin

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk