[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Mutex, Take 3 (for "dumb" futex)
- From: "Alexander Terekhov" <TEREKHOV de ibm com>
- To: phil-list redhat com
- Subject: Mutex, Take 3 (for "dumb" futex)
- Date: Sat, 25 Oct 2003 22:59:20 +0200
http://people.redhat.com/drepper/futex.pdf
("Mutex, Take 1" ... "Mutex, Take 2")
struct Mutex_Take_3 { // for "dumb" futex
futex lock; // 0: free, 1: locked, 3: contention
void lock() {
if (lock.atomic_bit_test_set(1))
while (lock == 3 || lock.atomic_exchange(3))
lock.wait(3);
}
void unlock() {
if (lock.atomic_exchange(0) == 3)
lock.wake(1);
}
}; // no CAS (long live "dumb" 386)
;-)
regards,
alexander.
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]