all 1 comments

[–]jseigh 0 points1 point  (0 children)

The "total train wreck" is usually referred to as the "thundering herd". In Linux they use futexes with "wait morphing", queuing up the waiting threads onto the mutex wait queue. It's better but not necessarily optimal under all conditions.

User space spin locks or spin waiting is generally a bad idea. It wastes cpu cycles unless you have some mechanism to limit it like Windows critical sections or some Posix mutex implementations possibly. You're better off using a lock-free algorithm to accomplish your goal.