Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2005

Tip: Looking for answers? Try searching our database.

How emulate pthread condition variables in native Windows?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
noleander - 02 Jun 2005 03:03 GMT
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
William DePalo [MVP VC++] - 02 Jun 2005 03:38 GMT
> I've got an application that uses Pthread to do threading.  Mostly Im
> using
[quoted text clipped - 16 lines]
>
> 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
Carl Daniel [VC++ MVP] - 02 Jun 2005 03:42 GMT
>> I've got an application that uses Pthread to do threading.  Mostly Im
>> using
[quoted text clipped - 25 lines]
>
> which I believe has support for Posix Threads.

And which appear to be free.

http://www.microsoft.com/windowsserversystem/sfu/downloads/default.mspx

-cd
noleander - 02 Jun 2005 04:03 GMT
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.

> >> I've got an application that uses Pthread to do threading.  Mostly Im
> >> using
[quoted text clipped - 31 lines]
>
> -cd
William DePalo [MVP VC++] - 02 Jun 2005 05:19 GMT
> 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
William DePalo [MVP VC++] - 02 Jun 2005 05:57 GMT
> 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
William DePalo [MVP VC++] - 02 Jun 2005 04:58 GMT
> And which appear to be free.
>
> http://www.microsoft.com/windowsserversystem/sfu/downloads/default.mspx

Who woulda thunk that! :-)

Regards,
Will
Doug Harrison [MVP] - 02 Jun 2005 07:27 GMT
> I've got an application that uses Pthread to do threading.  Mostly Im using
> Condition Variables and the associated function calls:
[quoted text clipped - 15 lines]
> 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

Signature

Doug Harrison
Microsoft MVP - Visual C++

noleander - 02 Jun 2005 13:51 GMT
Thanks for that article ... it looks like it fits my needs exactly.

Here is another article I just found that has some similar suggestions, tho
not couched in "condition variable" terminology:

http://www.codeproject.com/threads/semaphores.asp

Thanks again!

> > I've got an application that uses Pthread to do threading.  Mostly Im using
> > Condition Variables and the associated function calls:
[quoted text clipped - 20 lines]
> Strategies for Implementing POSIX Condition Variables on Win32
> http://www.cs.wustl.edu/~schmidt/win32-cv-1.html 
Carl Daniel [VC++ MVP] - 02 Jun 2005 15:09 GMT
> 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

Unfortunately it looks like they never got around to finishing part 2 of the
article.

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

..but the solutions in part 1 are probably acceptable for most uses.

-cd
Doug Harrison [MVP] - 02 Jun 2005 19:07 GMT
>> Here's a good paper on the subject:
>>
[quoted text clipped - 7 lines]
>
> ..but the solutions in part 1 are probably acceptable for most uses.

With that in mind, I'd definitely check out the link to ACE at the bottom
of the article, where they say they actually implement the ideas presented
in the paper.

Signature

Doug Harrison
Microsoft MVP - Visual C++


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.