I want to implement something similar to InitializeCriticalSectionAndSpinCount, but more portable. I find implementation of spinlock in Boost, but in documentation we can read:
The purpose of a spin lock is to prevent multiple threads from concurrently accessing a shared data structure. In contrast to a mutex, threads will busy-wait and waste CPU cycles instead of yielding the CPU to another thread.
So it's not that same that Windows InitializeCriticalSectionAndSpinCount
When a thread tries to acquire a critical section that is locked, the thread spins: it enters a loop which iterates spin count times, checking to see if the lock is released. If the lock is not released before the loop finishes, the thread goes to sleep to wait for the lock to be released.
Because in boost thread not goes to sleep?
I also found Implementing a spinlock in Boost. Example Needed
I think it's provide different mechanism that InitializeCriticalSectionAndSpinCount or maybe I'm in mistake?