boost::detail::spinlock problem
Cliff Diamond via Boost-users <[email protected]> Wed, 21 Dec 2022 17:10:55 +0000
| Newsgroups | gmane.comp.lib.boost.user |
|---|---|
| Message-ID | <LO0P265MB4573189E6204803E5D6A4232D2EB9@LO0P265MB4573.GBRP265.PROD.OUTLOOK.COM> |
Hi I'm using boost::detail::spinlock (boost-1.81) in code that compiles on both Visual Studio and gcc. I've hit a problem on the gcc build where the underlying spinlock member (v_) in spinlock_gcc_atomic.hpp isn't an atomic variable and isn't explicitly initialised (BOOST_DETAIL_SPINLOCK_INIT is defined, but there's no initializer and no constructor). v_ is declared as a non-atomic unsigned char and atomic operations use gcc intrinsics in that file. So v_ needs to be explicitly initialized to 0. When the lock method is called, it just spins as a result. This may be work-in-progress or am I misunderstanding? It seems such a glaring omission. The STL version of the spinlock uses std::atomic which does initialize v_ because it's wrapped up in the atomic template. Also there is a scoped_lock nested class within the boost spinlock. Why have an additional lock guard? Surely std::scoped_lock should be sufficient (or is it there just for testing - if so please comment it). I can overcome the problem (without modifying spinlock_gcc_atomic.hpp) by trying to acquire the lock when I create it and releasing it regardless. Is this a bug in that file? Thanks Cliff _______________________________________________ Boost-users mailing list [email protected] https://lists.boost.org/mailman/listinfo.cgi/boost-users