mutex and condition variable implementation using futex

567 views
Skip to first unread message

Sudhanshu Shukla

unread,
Aug 10, 2011, 12:41:45 AM8/10/11
to lock...@googlegroups.com
Hi Group,

I do not know if this is the correct platform to ask this question. If it is not kindly ignore the post.

I have implemented mutex and condition variables using futex syscall. The code is attached with this mail. I believe that my implementation is correct, but would like it to be verified by some one else. If any of you could take a look at it, it would be very helpful. 

Any suggestions for further improving the performance would be greatly appreciated.


Thanks
Sudhanshu 
synchronization.h

Keith H Duggar

unread,
Aug 10, 2011, 8:16:37 AM8/10/11
to Scalable Synchronization Algorithms
On Aug 10, 12:41 am, Sudhanshu Shukla <sudhan...@gmail.com> wrote:
> I have implemented mutex and condition variables using futex syscall. The
> code is attached with this mail. I believe that my implementation is
> correct, but would like it to be verified by some one else. If any of you
> could take a look at it, it would be very helpful.
>
> Any suggestions for further improving the performance would be greatly
> appreciated.

If you haven't seen this already, this article may be helpful to you:

http://locklessinc.com/articles/mutex_cv_futex/

Also, you can look at the GNU pthread implementations for Linux which
use futex.

KHD

Dmitriy V'jukov

unread,
Aug 10, 2011, 2:59:39 PM8/10/11
to lock...@googlegroups.com

Hi Sudhanshu,

I can't spot any issues at a glance.

As for performance, perhaps you don't want to do the syscall in
signal/broadcast if there are no waiters. However it depends on you
use cases - sometimes people call signal/broadcast every here and
there, if you are going to call them iff there are waiters with high
probability, then the optimization has little sense.

You may also take a look at the mutex that I recently submitted to Go
language runtime:
http://code.google.com/p/go/source/browse/src/pkg/runtime/linux/thread.c

Reply all
Reply to author
Forward
0 new messages