This is the mail archive of the
pthreads-win32@sources.redhat.com
mailing list for the pthreas-win32 project.
Re: Mutex implementation questions
- To: Tristan Savatier <tristan at mpegtv dot com>
- Subject: Re: Mutex implementation questions
- From: Ross Johnson <rpj at ise dot canberra dot edu dot au>
- Date: Tue, 03 Oct 2000 17:36:38 +1100
- CC: "'pthreads-win32 at sources dot redhat dot com'" <pthreads-win32 at sources dot redhat dot com>
- Organization: University of Canberra, Information Sciences and Engineering
- References: <430F887D415DD1118C2700805F31ECF1037F1388@SOTA0005> <39D907CE.29E2E536@mpegtv.com>
Tristan Savatier wrote:
>
> I noticed that if _pthread_try_enter_critical_section has been set
> to a non-NULL value by DllMain, Mutexes are implemented using
> critical sections (InitializeCriticalSection) instead of
> CreateMutex, regardless of the value of the implemetation-specific
> forcecs
> mutex attribute.
>
> According to "Win32 programming", critical sections are light weight
> compared to mutexes, they are not managed by the kernel, and they
> are much faster than mutexes. So why no use critical sections
> all the time to implement pthread mutexes ?
>
Win9x doesn't support TryEnterCriticalSection, hence the fallback
to Win32 mutexes on those platforms. On Win98 that function
appears to be a stub that does nothing hence the need to test it
by actually initialising a CS and attempting to acquire it.
The forcecs hook is there if your application never needs to use
pthread_mutex_trylock() and you want the performance advantage.
It could perhaps be better implemented as a non-portable per
mutex attribute (or either option could be provided).
> It might be a good idea to add a compile flag to
> allow the use of pthread-win32 with static linking
> (i.e. to make just a pthread.lib, no dll).
>
> In this case, a compilation flag should be added to exclude the DllMain
> routine. Also, the code that sets _pthread_try_enter_critical_section
> should be moved from DllMain to _pthread_processInitialize. The
> _pthread_processInitialize should be made global and it should
> be called by the application to initialize pthread.
This sounds like a good idea for static linked libraries.
Cheers.
Ross
--
+----------------------+---+
| Ross Johnson | | E-Mail: rpj@ise.canberra.edu.au
| Info Sciences and Eng|___|
| University of Canberra | FAX: +61 6 2015227
| PO Box 1 |
| Belconnen ACT 2616 | WWW: http://willow.canberra.edu.au/~rpj/
| AUSTRALIA |
+--------------------------+