Boost logo

Boost :

From: William E. Kempf (wekempf_at_[hidden])
Date: 2003-04-28 12:22:54


Bronek Kozicki said:
> William E. Kempf wrote:
>>> Could this not have been implemented with a critical section and use
>>> TryEnterCriticalSection? Why was the mutex approach used for one and
>>> not the other?
>>
>> TryEnterCriticalSection is not portable. Specifically, it's not
>> available in the Win9x line.
>
> Critical sections in Win32 are much more efficient than mutexes, which
> sometimes is important thing in multithreaded programs - especially
> those running on servers.

There's some debate about that. Timings show that this isn't necessarily
true... especially on multi-processor machines with high contention rates.
 But at a generic level, I agree with you.

> It would be nice to use them in compatible
> environment ie. WinNT family . There could be some switch like:
> #define BOOST_THREAD_WIN32_USE_CRITICAL_SECTION
> which will force use of critical section instead of mutex. Of course
> program compiled with this switch might not run in Win9x, which is fine.
> If anybody wants to use mutex (ie. compile for compatibility with old
> environment) , he/she will just not define above mentioned symbol. I
> hope this proposal will not introduce maintenance nightmare.

A compiler switch isn't the answer. OS detection is what I'm currently
using in the next version.

-- 
William E. Kempf

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk