Boost logo

Boost Users :

Subject: Re: [Boost-users] [Thread][win32, msvc] Mutexes
From: Alexander Gutenev (gutenev_at_[hidden])
Date: 2008-09-28 05:40:46


"Anthony Williams" <anthony.ajw_at_[hidden]> writes:

>> 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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net