
"Anthony Williams"
boost::mutex isn't CRITICAL_SECTION, but boost::detail::lightweight_mutex is. Does this mean that boost::mutex is heavy-weight ?
No. boost::mutex is a lightweight mutex. It has slightly different performance characteristics than CRITICAL_SECTION: it is intended to be "better" than CRITICAL_SECTION.
I tried to measure performance of a loop of lock/unlock loop without actual concurrency. I think this still an use case: double d_; mutex m_; ... // then, in a loop: m_.lock(); d_ += d; m_.unlock(); // it's rarely ever be waiting for a lock, but mutex is needed for correctness anyway. CRITICAL_SECTION performed slightly better. I attitude the difference to ::boost::detail::get_system_time_sentinel() object construction on each lock() call.
If not so, what's the reason for boost::detail::lightweight_mutex to exist ?
I think it's a historic artifact from versions of boost.thread prior to 1.35.0 when boost::mutex required linking to the thread library, which allowed mutexes to be used in header-only boost libraries.
I see. Not historic, actually. I had to build date_time library to use mutexes.