3 ms·
I attempted to address these concerns using an adaptive algorithm in glibc some 15 years ago: http://stackoverflow.com/questions/19863734/what-is-pthread-mutex
by kazinator 11y ago
I attempted to address these concerns using an adaptive algorithm in glibc some 15 years ago:
http://stackoverflow.com/questions/19863734/what-is-pthread-mutex-adaptive-np/#25168942 http://stackoverflow.com/questions/19863734/what-is-pthread-...
The idea is to avoid spinning using hard-coded constants, but put a modicum of on-the-fly empirical science into it: measure the duration of the critical regions with a smoothed estimator, which is maintained in the mutex. If the actual wait exceeds this smoothed average by too much (say double) then conclude that the owner must be pre-empted and break the spin with rescheduling.
The smoothing is done very easily using a few bit operations that implement an IIR filter, similarly to the TCP RTO estimator.