java - How is mutex internally implemented -
i've spent time trying understand how mutexes implemented in several languages. there multiple links describing topic (*) if understand correctly, hardware provides atomic operations may distinguish should in turn now.
in software used busy waiting (try cas or test-and-set , wait in while cycle if not successful), how scheduler know should take away process/thread cpu because waits? there support in os provided example java synchronization uses in order signal "i blocked, please let other threads run instead"? think is, since busy-waiting alternative use lock(); (so should not same)
*source:
in linux jdk soure c code uses pthread
library part of standard c library. that, in turn, uses linux kernel futex
feature (man futex
). far can understand, implemented using kernel scheduler put calling thread sleep , wake when signal received.
scheduler relies on timer interrupts (hardware) work -- essentially, everytime timer interrupt arrives, scheduler has check if current user-space thread wants/must suspended and, if yes, must choose other thread.
here few further links more clear , detailed explanation:
- http://man7.org/linux/man-pages/man7/futex.7.html
- http://www.quora.com/how-different-is-a-futex-from-mutex-conceptually-and-also-implementation-wise
- book robert love's
linux kernel development
(but, oddly enough, not contain single mention offutex
) , book (which contain futex mentions in references external papers): kerrisk'sthe linux programming interface
.
Comments
Post a Comment