Case Study: Linux Futex (Fast Userspace Mutex)
#include <linux/futex.h> #include <sys/time.h> int futex(int *uaddr, int futex_op, int val, const struct timespec *timeout);
T&S and Futex
acquire(int *thelock) {
while(__atomic_test_and_set(thelock, __ATOMIC_SEQ_CST)) {
futex(thelock, FUTEX_WAIT, 1);
}
}
release(int *thelock) {
thelock = 0;
futex(thelock, FUTEX_WAKE, 1);
}Last updated