How emulate pthread condition variables in native Windows?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've got an application that uses Pthread to do threading. Mostly Im using
Condition Variables and the associated function calls:

- pthread_cond_wait()
- pthread_cond_signal()
- pthread_cond_broadcast()

My boss says we cant use Pthread because of licensing issues (LGPL) .. we
can only use Native Win32 threading/mutex functions.

Question: Does anyone out there have any suggestion on how to implement
Condition Variables with Native Win32 functions?

I researched this in the web, but the only thing I could find (besides
PThread) was the function PulseEvent ... but the MS documentation says that
function is not reliable and should not be used.

Thanks in advance for any help,
neal
 
noleander said:
I've got an application that uses Pthread to do threading. Mostly Im
using
Condition Variables and the associated function calls:

- pthread_cond_wait()
- pthread_cond_signal()
- pthread_cond_broadcast()

My boss says we cant use Pthread because of licensing issues (LGPL) .. we
can only use Native Win32 threading/mutex functions.

Question: Does anyone out there have any suggestion on how to implement
Condition Variables with Native Win32 functions?

I researched this in the web, but the only thing I could find (besides
PThread) was the function PulseEvent ... but the MS documentation says
that
function is not reliable and should not be used.

Thanks in advance for any help,

First the disclaimer: I know nothing of 'nix, 'nux and 'pux.

If however, you are willing to consider buying some help, you can look at
Services for Unix:

http://www.microsoft.com/technet/interopmigration/unix/sfu/pthreads0.mspx

which I believe has support for Posix Threads.

In addition, native Windows has support for mutexes, semaphores, events and
critical sections ( check the docs for CreateMutex(), CreateSemaphore(),
CreateEvent() and InitializeCriticalSection() ). You should be able
implement the missing pthread calls with a handful of these synchronization
services.

Regards.
Will
 
Thanks for the suggestions.

I tried SFU a few months ago and I had two problems with it: (1) im using
Standard Vis C++, and I think it required me to buy the more expensive
edition; and (2) it was _huge_.

I'm looking for just a little wrapper around the native Windows thread
library that emulates the pthread Condition Variable functions.

I've read the Pthread (for Windows) source code, and it is rather elaborate
.... I was hoping someone has created a stripped-down, simple wrapper that
does condition variables.
 
noleander said:
Thanks for the suggestions.

You are welcome.
I tried SFU a few months ago and I had two problems with it: (1) im
using
Standard Vis C++, and I think it required me to buy the more expensive
edition;

Well, I don't know if that is true but if you post information on whatever
it was that you could not do with the standard edition, someone will likely
be able to confirm that or explain why it is not so.
and (2) it was _huge_.

Well, Windows ain't 'Nix. :-)

Regards,
Will
 
noleander said:
I've read the Pthread (for Windows) source code, and it is rather
elaborate
... I was hoping someone has created a stripped-down, simple wrapper that
does condition variables.

Underlying that wish is the assumption that the wrapper ought to be simple.

At this link you'll find a paper on synthesizing condition variables under
Win32:

http://www.cs.wustl.edu/~schmidt/win32-cv-1.html

It contains this line

<quote>
This article illustrates why developing condition variables on Win32
platforms is tricky and error-prone
</quote>

Were I you in your shoes, I might be tempted to use what the author has to
offer here:

http://www.cs.wustl.edu/~schmidt/ACE.html

if the licensing terms (which I did not research) are acceptable, regardless
of perceived lack of simplicity. Just my opinion, YMMV.

Regards.
Will
 
I've got an application that uses Pthread to do threading. Mostly Im using
Condition Variables and the associated function calls:

- pthread_cond_wait()
- pthread_cond_signal()
- pthread_cond_broadcast()

My boss says we cant use Pthread because of licensing issues (LGPL) .. we
can only use Native Win32 threading/mutex functions.

Question: Does anyone out there have any suggestion on how to implement
Condition Variables with Native Win32 functions?

I researched this in the web, but the only thing I could find (besides
PThread) was the function PulseEvent ... but the MS documentation says that
function is not reliable and should not be used.

Thanks in advance for any help,
neal

Here's a good paper on the subject:

Strategies for Implementing POSIX Condition Variables on Win32
http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
 
Back
Top