尝试锁定 Windows
在pthread库中可以找到非阻塞函数:
int pthread_mutex_trylock(pthread_mutex_t *mutex);
我可以在Windows
中找到类似的东西吗?
in pthread library it is possible to find non blocking function:
int pthread_mutex_trylock(pthread_mutex_t *mutex);
can I find something similar in Windows
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用锁的关键部分,则等效内容为
TryEnterCriticalSection()
。如果您使用互斥锁作为锁,则等效方法是调用
WaitForSingleObject()
传递0
作为超时。如果您不熟悉 Windows 同步对象,请不要被愚弄而更喜欢互斥体,因为它有一个您在 pthread 背景中最熟悉的名称。只要您的同步在进程内,关键部分就会更高效且更易于使用。
If you are using a critical section for your lock then the equivalent is
TryEnterCriticalSection()
.If you are using a mutex for your lock then the equivalent is to call
WaitForSingleObject()
passing0
as the timeout.If you are unfamiliar with Windows synchronisation objects, don't be fooled into preferring the mutex because it has a name that you are most familiar with from a pthreads background. So long as your synchronisation is within process, critical sections are more efficient and easier to use.
您可以检查 Boost 库。他们有一个叫做shareable_locks的东西。< br>
这是 Boost Interprocess Library 的一部分,适用于Windows 和 Unix。
You could check the Boost library. They have something called shareable_locks.
This is part of the Boost Interprocess Library which works in both Windows and Unix.