tags:

views:

66

answers:

2

Hi,

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?

A: 

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);
Hans Passant
I've already tried that but both ways compile and work just fine. I'm using VS2008 by the way.
O. Askari
Ditch the library. CreateMutex, WaitForSingleObject, ReleaseMutex gets it done on Windows.
Hans Passant
@nobugz, Thanks. It seems its the only way :)
O. Askari
A: 

good advice to write portable code ;)

jamesvista