|
Defect of pthread_mutex_trylock implementation
|
02/05/2010 12:13 PM
post46697
|
Defect of pthread_mutex_trylock implementation
In pthread_mutex_trylock()
----------
// Static intialized. Do an immediate tineout so no threads block.
if(owner == _NTO_SYNC_INITIALIZER) {
(void)TimerTimeout_r(CLOCK_REALTIME, _NTO_TIMEOUT_MUTEX, NULL, NULL, NULL);
if((ret = SyncMutexLock_r((sync_t *)mutex)) != EOK) {
return ((ret == ETIMEDOUT) ? EBUSY : ret);
}
++mutex->__count;
return EOK;
}
----------
It is illegal to use CLOCK_REALTIME for setting up zero timeout here (just like anywhere else!). If system clock is
adjusted (rewound back) in between of TimerTimeout() and SyncMutexLock_r() calls, the thread will block until clock
catches up to the realtime value that was there at the moment of TimerTimeout call or until mutex is unlocked. For
timeouts only CLOCK_MONOTONIC clock should be used.
|
|
|