Boost logo

Boost Users :

From: Mark Sizer (yg-boost-users_at_[hidden])
Date: 2003-07-31 16:42:59


Generically, the difference between critical sections and mutexes is
immense. In terms of implementation, one never knows.

A critical section blocks EVERYTHING else in the process. A mutex only
blocks things that are waiting on that particular mutex.

If one is actually getting parallel processing (i.e. multi-processor
machine), mutexes can be far more performant because only stuff that
needs to block does - everything else keeps going. Critical sections are
much easier to manage - in a way they're like a single global mutex.
Deadlocks are much more difficult.

Back in the day (NT 3.51), Windows was much more (two orders of
magnitude) efficient with critical sections than with mutexes. That may
no longer be true (I hope not, I'm using boost mutexes, now). Threading
under Windows is not such a good idea anyway, with the exception of
things that block anyway (e.g. I/O, client/server RPC, etc...). Windows
doesn't deal well with more than two processors, so what's the point of
having dozens of threads? They won't run in parallel anyway. State-based
event engines tend to perform better than multithreading, although I
find them nightmarish to debug.

I have no clue what any other platform does. I'm hoping Linux scales to
multiprocessor systems better, but while I've ported the code, I haven't
run any tests, yet. Anyone have an 8-processor Linux box they want to
loan me?

- Mark

Paul Grenyer wrote:

> On Thu, 2003-07-31 at 19:48, Jason Winnebeck wrote:
>
> Hi
>
>
>>How do you think mutex and CS differ? From what I understand they
>>perform the same purpose. Win32 CS's are recursive lockable, I believe
>>that is an option or an ability of the boost mutex as well. I wouldn't
>>be surprised if it was implemented as CS's in Win32.
>>
>
> I'm wasn't sure there was a difference. I've used Critical Sections
> before by not mutexes. If they're the same (or similar) so much the
> better!
>
>


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