bloomberg / quantum

Powerful multi-threaded coroutine dispatcher and parallel execution engine
Apache License 2.0
572 stars 94 forks source link

Inefficient SpinLock implementation #123

Closed anton-malakhov closed 4 years ago

anton-malakhov commented 4 years ago

Describe the bug SpinLock as it is implemented in Quantum kills neighbor HyperThread performance and consumes excessive power.

Proposal Use PAUSE instruction (_mm_pause(); intrinsic) for short-duration lock. Use a back-off algorithm to gradually reduce bus traffic used for the atomic checks. Insert co-op yield point if it takes too long to acquire the lock.

Additional context

accelerated commented 4 years ago

Hi @anton-malakhov, yes the current implementation is rather simplistic. Given enough time I will look into this. However would you like to propose a PR instead? I notice boost has a cross-platform implementation which could potentially be used.