Ales Lacen(deleted)
|
pthread_cond_timedwait returns errorcode EBUSY
|
Ales Lacen(deleted)
08/13/2010 7:09 AM
post62912
|
pthread_cond_timedwait returns errorcode EBUSY
Hello,
I posted by mistake the same bug under topc15348 in QNX4 Community Support - Forum, but we are using Qnx Momentics 6.4.
1 so I think here it is wrightly placed.
I have some applications, which return at call of pthread_cond_timedwait the errorcode 16 (EBUSY).
In the manual its written, that this errorcode is for this function not possible.
The case is, when I call pthread_cond_wait() instead of pthread_cond_timedwait() than everything is fine.
So I would think, the condition variable and mutex variable, would be passed wright.
And the third parameter (abstime) I exemined by call of pthread_cond_timewait looks well either.
Could anyone give me tip?
I suppose there is a problem with unlocking the passed mutex in the pthread_cond_timedwait() - procedure, but
unfortunately I can't debug into it.
I suppose the topc14006 is a similar problem. Maybe there is a problem in the mutex-handling of qnx?
here the code snipped:
static OS_ErrorCode os_waitForCondition(OS_Event* ev, OS_NanoSec durationTime)
{
int err;
struct timespec spec;
OS_NanoSec targetTime;
if (!ev)
{
tPrintf(TRC_FAULT | TRC_COSA, "%s: Invalid parameter", __FUNCTION__);
return OS_InvalidParam;
}
pthread_mutex_lock((pthread_mutex_t*) &(ev->mutex));
if (ev->signaled)
{
if (!ev->manualReset)
ev->signaled = OS_FALSE;
pthread_mutex_unlock(&ev->mutex);
return OS_Success;
}
if (durationTime != OS_INFINITE)
{
OS_ErrorCode r = os_getCurrentTime(&targetTime);
if (r != OS_Success)
{
pthread_mutex_unlock(&ev->mutex);
return r;
}
targetTime += durationTime;
if(targetTime > 1000000000ULL)
spec.tv_sec = /*(time_t)*/ (targetTime / 1000000000ULL);
else
spec.tv_sec = 0;
spec.tv_nsec = (long) (targetTime % 1000000000ULL);
err = pthread_cond_timedwait((pthread_cond_t *)&(ev->cond), (pthread_mutex_t *)&(ev->mutex), (const struct timespec*)&spec)
;
}
else
err = pthread_cond_wait(&ev->cond, &ev->mutex);
switch (err)
{
case 0:
if (!ev->manualReset)
ev->signaled = OS_FALSE;
pthread_mutex_unlock((pthread_mutex_t*) &ev->mutex);
return OS_Success;//signaled!
case ETIMEDOUT:
pthread_mutex_unlock((pthread_mutex_t*) &ev->mutex);
return OS_Timeout;
default:
tError(TRC_FAULT | TRC_COSA, err, "%s", __FUNCTION__);
break;
}
pthread_mutex_unlock((pthread_mutex_t*) &ev->mutex);
return OS_Error;
}
I have found a solution to avoid this problem, but I think this is not a clean one. And furthermore I don't understand
it!
If I insert this
struct timespec sl;
sl.tv_sec = 0;
sl.tv_nsec = 1;
nanosleep(&sl, NULL); //1 nanosec verzögern
directly after the row with
if (durationTime != OS_INFINITE)
{
then everything is fine.
With best regards
Ales Lacen
|
|
|