linux - How pthread_mutex_lock is implemented -


i curious know how functions related synchronization between processes , threads implemented inside unix means happens when call pthread_mutex_lock?? pointers?? or source code help.

it both complicated , differs unix unix variant.

in linux, example, system called futex (short fast userspace mutex) used.

in system atomic increment , test operation performed on mutex variable in user space.

if result of operation indicates there no contention on lock, call pthread_mutex_lock returns without ever context switching kernel, operation of taking mutex can fast.

only if contention detected system call (called futex) , context switch kernel occurs puts calling process sleep until mutex released.

there many many more details, reliable and/or priority inhertience mutexes, essence of it.

for more details see: http://linux.die.net/man/2/futex , http://en.wikipedia.org/wiki/futex


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -