Overview
Features
Download
Documentation
Community
Add-Ons & Services

Mutex implementation on Win32

General discussion regarding the development of POCO for contributors.

Mutex implementation on Win32

Postby JProgrammer » 17 Jul 2008, 09:13

I was just curious as to why poco uses what amounts to a spin lock for the implementation of Mutex?

Buy using a CRITICAL_SECTION you cannot to a timed acquire. However if you used a Mutex by using CreateMutexW as you have already in the RWLock and NamedMutex you would remove the need for the Thread::sleep().
JProgrammer
 
Posts: 1
Joined: 17 Jul 2008, 04:02
Location: Other

Re: Mutex implementation on Win32

Postby guenter » 17 Jul 2008, 09:49

Operations on a Mutex are magnitudes slower than operations on a CRITICAL_SECTION, that's the main reason (I did a performance comparison once, and there was a huge difference; unfortunately I don't remember the exact numbers). The reason is that Mutex is a kernel object and every operation has to be done through the kernel, which seems to be very slow on Windows. CRITICAL_SECTION is implemented in user space, and its implementation is very efficient (inlining, etc.)

The timed wait operation is a recent addition, so we did not have the problem in the original design. However, the performance benefits of CS and the fact that a time wait is not used very often still make CS the preferred mechanism to implement the Mutex.
guenter
 
Posts: 1092
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Re: Mutex implementation on Win32

Postby Standard » 19 Jul 2008, 19:57

While it is true that using a mutex is remarkably slower it is not very consequent not to use a mutex in a class called Mutex.
Especially when it comes to support the waitable issue.

However I'd rather suggest to offer an additional class which is based on a critical section (FastMutex or however you'll name it) and make the current Mutex based on a real mutex on Win32.

Just my 2 cents ;D

Standard
Standard
 
Posts: 4
Joined: 30 Jun 2008, 14:23
Location: Germany


Return to Contributors

Who is online

Users browsing this forum: No registered users and 1 guest

cron