|
|
Back to UserFriendly Strip Comments Index
|
ok, stuttering sound after program crash in Linux | by confused.brit | 2009-03-31 13:27:55 |
|
Hmm, what does Futex_wait mean? | by confused.brit | 2009-03-31 13:48:05 |
| Futexes are "fast mutexes". |
by bwkaz |
2009-03-31 21:32:42 |
A mutex is an object used for inter-thread synchronization: it can be held either by one thread, or by zero threads.
When a thread (thread 1) tries to acquire a mutex, it will get the mutex if no other thread currently has it. If some other thread (thread 2) does have it, then thread 1 will wait until thread 2 releases the mutex, at which point thread 1 will get it. In either case, when the acquire call returns, thread 1 will have the mutex, and no other thread will. Thread 1 may or may not have gone to sleep in the meantime.
("Mutex" is short for "mutual exclusion": at most one thread may own it at any one time.)
Anyway, with normal mutexes, there's a system call into the kernel when a thread wants to either acquire or release the mutex. System calls take quite a bit of time. A futex can be acquired entirely in userspace, as long as no other thread owns it. (The kernel must get involved to put one thread to sleep until the other thread releases the futex, so if one is owned and then subsequently acquired, the kernel must get involved.)
In any case, contention on a mutex is generally the rare case; normally there is no contention. This means that a futex is a huge performance win in the common case, since the kernel doesn't have to get involved most of the time.
FUTEX_WAIT, though, is the operation that gets sent to the kernel when it *does* need to get involved: when a thread tries to acquire a futex but it's already owned by another thread. This probably means that whoever wrote PulseAudio (or in Ubuntu's case, whoever I assume modified it -- PA is supposed to be "lock-free" according to at least one blog post by the author...) added a whole bunch of lock contention that likely shouldn't be there... |
|
[ Reply ] |
|
|
[Todays Cartoon Discussion]
[News Index]
|
|