Maybe it's a terminology thing. In Win32 the difference between a critical
section and a mutex is that a mutex is a system wide object (ie it is known
in other processes) and a critical section is only available to the threads
of one process.
A critical section can only block those threads that choose to Enter it in
the same way as a mutex can only block those threads that choose to Wait on
it.
I have not done any performance testing but one would expect critical
sections to perform better because they are (mostly) non-kernel code.
Best - Richard
----- Original Message -----
From: "Mark Sizer"
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!
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/