2014-05-02 13:26 GMT+04:00 Giovanni Piero Deretta
On Fri, May 2, 2014 at 6:37 AM, Antony Polukhin
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