Bookmarks for 2023-11-28
5 bookmarks were saved this day.
5 bookmarks were saved this day.
This is an opinionated essay about good and bad practices in data visualization. Examples and explanations are below.
How to spin before sleeping so that it actually helps and not harms?
Microbenchmark for futexes + spinlocks and some useful links at the bottom.
Because spin locks are so simple and fast, it seems to be a good idea to use them for short-lived critical sections. For example, if you only need to increment a couple of integers, should you really bother with complicated syscalls? In the worst case, the other thread will spin just for a couple of iterations…
Unfortunately, this logic is flawed! A thread can be preempted at any time, including during a short critical section. If it is preempted, that means that all other threads will need to spin until the original thread gets its share of CPU again. And, because a spinning thread looks like a good, busy thread to the OS, the other threads will spin until they exhaust their quants, preventing the unlucky thread from getting back on the processor!