
I started using the spinlock in boost/smart_ptr/detail/spinlock.hpp and discovered that it needs to be manually initialized, even for the spinlock_sync version, which became a nasty bug when it manifested itself. This seems a bit out of sync with the rest of the mutexes in boost::thread. Now, I'm guessing that the fact that the spinlock is in boost::detail means that it's not really for outside consumption (newbie boost user here), but is there something in the works that will be? In the meantime, would it be possible to automatically initialize the spinlock (trivial in the case of spinlock_sync) or are there architectural issues with that? Otherwise, could we add a comment that says "in order to use these spinlocks you must initialize with BOOST_DETAIL_SPINLOCK_INIT" or "move along, these aren't the spinlocks you're looking for."

On Sep 26, 2012, at 6:17 PM, Yi Ding <yi.s.ding@gmail.com> wrote:
I started using the spinlock in boost/smart_ptr/detail/spinlock.hpp and discovered that it needs to be manually initialized, even for the spinlock_sync version, which became a nasty bug when it manifested itself. This seems a bit out of sync with the rest of the mutexes in boost::thread.
Now, I'm guessing that the fact that the spinlock is in boost::detail means that it's not really for outside consumption (newbie boost user here), but is there something in the works that will be?
The detail namespace is so named because anything in it is an implementation detail. There is no documentation, you should expect no support, and you should expect breaking changes from one release to the next. (I have no idea whether there are or will be official alternatives for what you're using.) ___ Rob

Yi Ding wrote:
I started using the spinlock in boost/smart_ptr/detail/spinlock.hpp and discovered that it needs to be manually initialized, even for the spinlock_sync version, which became a nasty bug when it manifested itself. This seems a bit out of sync with the rest of the mutexes in boost::thread.
Now, I'm guessing that the fact that the spinlock is in boost::detail means that it's not really for outside consumption (newbie boost user here), but is there something in the works that will be?
In the meantime, would it be possible to automatically initialize the spinlock (trivial in the case of spinlock_sync) or are there architectural issues with that?
The spinlock is a POD, initialized with BOOST_DETAIL_SPINLOCK_INIT, so that the initialization is static and not dynamic, which is intended to prevent initialization order issues. If you want a dynamically initialized spinlock, you can create your own using boost::detail::spinlock as a basis, something like static boost::detail::spinlock initializer = BOOST_DETAIL_SPINLOCK_INIT; class my_spinlock { private: boost::detail::spinlock sl_; my_spinlock( my_spinlock const& ); my_spinlock & operator=( my_spinlock const& ); public: my_spinlock(): sl_( initializer ) {} // lock, unlock, try_lock, scoped_lock };
participants (3)
-
Peter Dimov
-
Rob Stewart
-
Yi Ding