0

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?

Community
  • 1
  • 1
DDD
  • 111
  • 7
  • Where is each quote from? The presentation is confusing. And what is your question? – Kerrek SB Oct 26 '14 at 15:34
  • First quote from boost documentation: http://www.boost.org/doc/libs/1_56_0/doc/html/atomic/usage_examples.html#boost_atomic.usage_examples.example_spinlock Second quote from: http://msdn.microsoft.com/en-us/library/windows/desktop/ms683476(v=vs.85).aspx and i think that my question is pretty clear. I ask about differencies between boost spinlock and windows InitializeCriticalSectionAndSpinCount, because i'm not pretty sure. – DDD Oct 26 '14 at 15:39
  • Well, the spin lock doesn't sleep, and the critical section does sleep... – Kerrek SB Oct 26 '14 at 15:51
  • Ok, so maybe there is some other solution / implementation that is better that out of box from boost ? I also look to topic: http://stackoverflow.com/questions/13014635/boost-mutex-implementation-for-windows and if i understand, standard mutex provide something like spinlock but on atomic variables ? – DDD Oct 26 '14 at 16:16

0 Answers0