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:

  1. http://man7.org/linux/man-pages/man7/futex.7.html
  2. http://www.quora.com/how-different-is-a-futex-from-mutex-conceptually-and-also-implementation-wise
  3. book robert love's linux kernel development (but, oddly enough, not contain single mention of futex) , book (which contain futex mentions in references external papers): kerrisk's the linux programming interface.

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -