如何在本机Windows中模拟pthread条件变量? [英] How emulate pthread condition variables in native Windows?

查看:96
本文介绍了如何在本机Windows中模拟pthread条件变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Pthread进行线程处理的应用程序。主要是我使用

条件变量和相关函数调用:


- pthread_cond_wait()

- pthread_cond_signal()

- pthread_cond_broadcast()

我的老板说我们因许可证问题(LGPL)而无法使用Pthread ..我们

只能使用Native Win32线程/互斥函数。


问题:有没有人有关于如何实现

条件变量与原生Win32函数的建议?


我在网上研究了这个,但我唯一能找到的东西(除了

PThread)就是函数PulseEvent ...但是MS文档说明了

功能不可靠,不应该使用。


提前感谢您的帮助,

neal

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" <无******* @ discussions.microsoft.com>在消息中写道

news:9C ********************************** @ microsof t.com ...
"noleander" <no*******@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.com...
我有一个使用Pthread进行线程处理的应用程序。主要是使用
条件变量和相关的函数调用:

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

我的老板说我们因为授权问题(LGPL)而无法使用Pthread ..我们
只能使用Native Win32线程/互斥功能。

问题:有没有人在那里有关如何使用Native Win32函数实现条件变量的任何建议吗?

我在网上研究了这个,但我唯一能找到的东西(除了
PThread)是函数PulseEvent ...但MS文档说

函数不可靠,不应该使用。

提前感谢您的帮助,
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,




首先是免责声明:我对''nix','nux和''pux一无所知。


但是,如果你愿意的话购买一些帮助,你可以看看

Unix服务:

http://www.microsoft.com/technet/int...pthreads0.mspx


我认为它支持Posix线程。


此外,本机Windows支持互斥,信号量,事件和

关键部分(检查CreateMutex(),CreateSemaphore(),

CreateEvent()和InitializeCriticalSection())的文档。您应该能够使用少数这些同步来实现丢失的pthread调用

服务。


问候。

Will



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/int...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


William DePalo [MVP VC ++]写道:
William DePalo [MVP VC++] wrote:
" noleander" <无******* @ discussions.microsoft.com>在消息中写道
新闻:9C ********************************** @ microsof t.com。 ..
"noleander" <no*******@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.com...
我有一个使用Pthread进行线程化的应用程序。主要是使用
条件变量和相关的函数调用:

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

我的老板说我们不能使用Pthread因为许可问题(LGPL)
..我们只能使用Native Win32线程/互斥功能。

问题:有没有人在那里有关如何使用Native Win32函数实现条件变量的任何建议吗?

我在网上研究了这个,但我唯一能找到的东西(除了PThread)是函数PulseEvent ...但MS
文档说
函数不可靠,不应该使用。

提前感谢您的帮助,
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,


然而,如果你愿意考虑购买一些帮助,你可以
http://www.microsoft.com/technet/int...pthreads0.mspx
<我认为它支持Posix Threads。



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/int...pthreads0.mspx

which I believe has support for Posix Threads.




这似乎是免费的。

http://www.microsoft.com/windowsserv...s/default.mspx


-cd



And which appear to be free.

http://www.microsoft.com/windowsserv...s/default.mspx

-cd


感谢您的建议。


我试过SFU几个月前和我有两个问题:(1)即时通讯使用

标准的Vis C ++,我认为它需要我买更贵的

版本; (2)它是_huge_。


我正在寻找一个围绕原生Windows线程的小包装器

模拟pthread条件变量的库函数。


我已经读过Pthread(对于Windows)的源代码,它相当精致

....我希望有人有创建了一个精简的简单包装器,

可以调节变量。

Carl Daniel [VC ++ MVP]"写道:
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.
"Carl Daniel [VC++ MVP]" wrote:
William DePalo [MVP VC ++]写道:
William DePalo [MVP VC++] wrote:
" noleander" <无******* @ discussions.microsoft.com>在消息中写道
新闻:9C ********************************** @ microsof t.com。 ..
"noleander" <no*******@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.com...
我有一个使用Pthread进行线程化的应用程序。主要是使用
条件变量和相关的函数调用:

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

我的老板说我们不能使用Pthread因为许可问题(LGPL)
..我们只能使用Native Win32线程/互斥功能。

问题:有没有人在那里有关如何使用Native Win32函数实现条件变量的任何建议吗?

我在网上研究了这个,但我唯一能找到的东西(除了PThread)是函数PulseEvent ...但MS
文档说
函数不可靠,不应该使用。

提前感谢您的帮助,
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,


然而,如果你愿意考虑购买一些帮助,你可以
http://www.microsoft.com/technet/int...pthreads0.mspx
<我相信它支持Posix Threads。



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/int...pthreads0.mspx

which I believe has support for Posix Threads.



这似乎是免费的。

http://www.microsoft.com/windowsserv...s/default.mspx

-cd



And which appear to be free.

http://www.microsoft.com/windowsserv...s/default.mspx

-cd



这篇关于如何在本机Windows中模拟pthread条件变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆