|
Returns a lock. Attempts to get the lock for specified time. Note that if you already locked an object, another Mutex_lock() operations does absolutely nothing, and the first Mutex_unlock() call unlocks it immediately no matter how many times you've called the Mutex_lock() method. Be careful when designing your Mutex logic! -
Parameters:
-
ptr_mutex
|
A pointer to the initialized Mutex object |
timeout
|
Determines how long wait if a lock can not be acquired (0 means forever) |
-
Returns:
-
TRUE if a lock was acquired, FLASE if timeout has expired
#include <cywin.h>
...
struct Mutex data_mutex;
...
Mutex_ctor( &data_mutex, "shared_data" );
...
if( Mutex_lock( &data_mutex, 1000 ) )
{
...
Mutex_unlock( &data_mutex );
}
else
{
TRACE( "Timeout while trying to access." );
}
...
Mutex_dtor( &data_mutex, LEAVE_MEMORY );
...
-
See also:
-
Mutex_unlock.
|