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. But when i use it with a time value (as follows) it just immediately returns with -1 value. I'm sure that this mutex hasn't been acquired anywhere else so it shouldn't return -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. 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. 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. 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. This is very fast but has no possibility to wait with a timeout.
Finally I used ACE_Process_Mutex instead of ACE_Mutex. This is implemented with a HANDLE -based mutex for win32 environments and can be used with timeout.
More information can be found here: http://flylib.com/books/en/3.19.1.83/1/#_/term_
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.