Previous | Next --- Slide 14 of 30
Back to Lecture Thumbnails
cacay

What type of lock generally does a Pthreads mutex use?

zhanpenf

This question is also asked on stackoverflow: http://stackoverflow.com/questions/5095781/how-pthread-mutex-lock-is-implemented

The answer says that it uses a system called futex which uses atomic increment and test operations on user space to implement the lock.

oulgen

Here is a software implementation of pthread mutex lock: ftp://sourceware.org/pub/pthreads-win32/sources/pthreads-w32-2-9-1-release/pthread_mutex_lock.c I believe this an implementation for windows 32 bit architecture. When though I'm not really sure how 32 bit versus 64 bit differs on this since the compiler should be able to deal with that.

oulgen

Also, after reading @zhanpenf's comment, I was curious about what futex's are and here is a great explanation I found on the internet: http://bartoszmilewski.com/2008/09/01/thin-lock-vs-futex/