Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
BroadcastCommunity.qnx.com will be offline from May 31 6:00pm until June 2 12:00AM for upcoming system upgrades. For more information please go to https://community.qnx.com/sf/discussion/do/listPosts/projects.bazaar/discussion.bazaar.topc28418
Forum Topic - Defect of pthread_mutex_trylock implementation: Page 1 of 3 (3 Items)
   
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.