简体   繁体   English

ACE_Mutex ::获取问题

[英]ACE_Mutex::acquire problem

I have a mutex in my class with the following definition: 我的班级中有一个互斥锁,定义如下:

ACE_Mutex m_specsMutex;

When i use the acquire() method that takes no parameters everything works just fine. 当我使用不带任何参数的acquire()方法时,一切正常。 But when i use it with a time value (as follows) it just immediately returns with -1 value. 但是,当我将其与时间值(如下所示)一起使用时,它立即返回-1值。 I'm sure that this mutex hasn't been acquired anywhere else so it shouldn't return -1. 我确定此互斥锁在其他任何地方都没有获得,因此它不应返回-1。

m_specsMutex.acquire(ACE_OS::gettimeofday() + ACE_Time_Value(30))

Am i doing anything wrong? 我做错什么了吗?

Browing through the doxygen docs for ACE_Mutex, I don't understand how your code could possibly compile. 浏览ACE_Mutex的doxygen文档,我不明白您的代码可能如何编译。 The time-out value (tv) is passed either by reference or a pointer so that acquire() can update the absolute time at which the mutex was acquired. 超时值(tv)通过引用或指针传递,以便acquire()可以更新获取互斥锁的绝对时间。 You cannot pass an expression. 您不能传递表达式。 Try it like this: 像这样尝试:

ACE_Time_Value time = ACE_OS::gettimeofday() + ACE_Time_Value(30);
m_specsMutex.acquire(&time);

I had the same problem on win32. 我在win32上遇到了同样的问题。 I needed much time to find a solution and want to share it with you. 我需要很多时间来找到解决方案,并希望与您分享。

ACE_Mutex (=ACE_Thread_Mutex) is implemented using CRITICAL_SECTION for win32 environments. ACE_Mutex(= ACE_Thread_Mutex)是针对Win32环境使用CRITICAL_SECTION实现的。 This is very fast but has no possibility to wait with a timeout. 这非常快,但是没有等待超时的可能性。

Finally I used ACE_Process_Mutex instead of ACE_Mutex. 最后,我使用了ACE_Process_Mutex而不是ACE_Mutex。 This is implemented with a HANDLE -based mutex for win32 environments and can be used with timeout. 对于Win32环境,这是通过基于HANDLE的互斥体实现的,并且可以与超时一起使用。

More information can be found here: http://flylib.com/books/en/3.19.1.83/1/#_/term_ 可以在这里找到更多信息: http : //flylib.com/books/en/3.19.1.83/1/#_/term_

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM