My platform is vs2010 win2003 server, I have an application working well. There is an integer protected by a critical section, when I modify and use boost::detail::spinlock instead then it goes to dead lock.
Asked
Active
Viewed 2,079 times
-2
-
Soooo what did you try to solve this problem? – Denis Ermolin Feb 05 '13 at 07:32
-
why the change was needed when it's working well ? BTW, is that the only change made ? – Jagannath Feb 05 '13 at 07:34
-
@DenisErmolin I use Interlockedxx api to solve it temporarily, but the true reason is still not found. – magicyang Feb 05 '13 at 07:37
-
@Jagannath For what the critical section protects is only an integer, so I want to use spinlock to improve the performance. I'm sure it's the only change made, for I use mutex or Interlocked the dead lock disappered. – magicyang Feb 05 '13 at 07:39
-
@magicyang: No, you want to use ATOMICs. Good news is that latest boost has them. – Jan Hudec Feb 05 '13 at 07:41
1 Answers
2
It's
boost::detail::spinlock
. That means it's intended for internal use only. If you want portable replacement for critical sections, useboost::mutex
from Boost.Thread.It's
boost::detail::spinlock
. Spinlocks usually busy-wait, which makes them faster, but usable only under tightly controlled conditions.Boost 1.53 (the latest release) finally got Boost.Atomic, which is a portable (and C++11 compatible) replacement for interlocked operations.

Jan Hudec
- 73,652
- 13
- 125
- 172
-
If it's only for internal use, maybe it's collapse with the smart pointer or others. I'll try the latest boost, thank you. – magicyang Feb 05 '13 at 07:53
-
1@magicyang: Boost often reimplements bits of generic infrastructure in the `details` subnamespace to keep the components independent. But doing this it makes various complex assumptions that are only true about the boost code, which makes these bits unusable in your own code. – Jan Hudec Feb 05 '13 at 08:04