Different OS, Different Support
This lesson discusses support provided by some other operating systems, specifically Linux.
We'll cover the following
You have thus far seen one type of support that an OS can provide in order to build a more efficient lock in a thread library. Other OS’s provide similar support; the details vary.
Futex
For example, Linux provides a futex which is similar to the Solaris interface but provides more in-kernel functionality. Specifically, each futex has associated with it a specific physical memory location, as well as a per-futex in-kernel queue. Callers can use futex calls (described below) to sleep and wake as need be.
Specifically, two calls are available. The call to futex_wait(address, expected)
puts the calling thread to sleep, assuming the value at address
is equal to expected
. If it is not equal, the call returns immediately. The call to the routine futex_wake(address)
wakes one thread that is waiting on the queue. The usage of these calls in a Linux mutex is shown below.
Get hands-on with 1400+ tech skills courses.