4 ms·
Hashing an address to map to a wait queue was done by early Unix kernels. The address was called a "wait channel" (wchan for short). There was no object decla
by kazinator 4y ago
Hashing an address to map to a wait queue was done by early Unix kernels.
The address was called a "wait channel" (wchan for short).
There was no object declared at the address; any object or function could be waited on.
The ps utility still has a field called "wchan" you can select, which tells you where the process is waiting.
Hashing is basically way to add properties to an object (identified by an address) without physically extending the structure located at that address.
We can give any address a wait queue, for instance.
E.g. Javascript object properties are like this. If we have some futex object in Javascript, and give it a futex.waitQueue property, it's basically the same: the futex thing is hashed somehow to access that property.
The main point of futexes is efficiency in the face of user/kernel separation. Futexes are intended to be used in a double-checked pattern, avoiding a call into the kernel. User space can check the state of the futex memory location and avoid calling wait. The wait operation in the kernel will do the same check again (this time atomically) possibly avoiding the wait.. If that weren't done, there would be a lost-wakeup problem in the use of mutexes.
Futexes are fast in the uncontended case; hence the F. Fast means in the context of the expensive user/kernel boundary. You would never need futexes without such a boundary; they are not used in the kernel. Futexes inside a single protection space are indeed a non-invention; the invention is the idea that something outside of the protected space can inspect the value and act on it.
- orf 4y ago> If we have some futex object in Javascript, and give it a futex.waitQueue property, it's basically the same: the futex thing is hashed somehow to access that property. I’m not sure that’s correct, it’s “waitQueue” that is hashed. In a super naive simple implementation the attributes are just a hash map.