hung pthread_cond_timedwait on uCLinux with v2linux

From: OferH (oferh_at_radlan.com)
Date: 06/27/04


Date: 27 Jun 2004 05:35:10 -0700

hi folks,

I have an application running on ARM946 with uClinux OS and Montavista
v2linux.
A thread performs a semaphore take (semTake) with timeout which
v2linux code implements (with conditional variable) as a call to
pthread_cond_timedwait. This call gets hung, I do not get a timeout
(ETIMEDOUT) or any other return code. It seems that the thread stack
got messed up somehow. If I change the call to a semTake(FOREVER) this
does not occure (i.e. the thread lives). If I replace the
pthread_cond_timedwait call with a delay of several seconds it does
not occure.
To disable the problem of stack overflow I created a new thread to
test this, here is the code:

unsigned __TASKCONV testTask(void)
{
    static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
    static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

    struct timeval now;
    struct timespec timeout;
    int retcode;

    if (pthread_mutex_lock(&mutex) != 0)
    {
        fprintf(stderr, "\r\n pthread_mutex_lock failed
%s",strerror(errno));
        exit(0);
    }

    while (1)
    {
        if (gettimeofday(&now, NULL) != 0)
        {
            fprintf(stderr, "\r\n gettimeofday failed
%s",strerror(errno));
        }
        timeout.tv_sec = now.tv_sec + 5;
        timeout.tv_nsec = now.tv_usec * 1000;

        fprintf(stderr, "\r\n before pthread_cond_timedwait");
        retcode = pthread_cond_timedwait(&cond, &mutex, &timeout);
        fprintf(stderr, "\r\n after pthread_cond_timedwait");

        if (retcode == ETIMEDOUT)
        {
            /* timeout occurred */
            fprintf(stderr, "\r\n retcode == ETIMEDOUT");
        }
        else
        {
            /* operate on x and y */
            fprintf(stderr, "\r\n retcode != ETIMEDOUT");
        }

        /*pthread_mutex_unlock(&mut);*/
    }
}

When running this thread I only see the "before
pthread_cond_timedwait" print!
Does anybody know of the same problem I have encountered? What am I
doing wrong?

Tx,
  Ofer



Relevant Pages

  • hung pthread_cond_timedwait on uCLinux with v2linux
    ... v2linux code implements as a call to ... I do not get a timeout ... It seems that the thread stack ... does not occure. ...
    (comp.os.linux.development.system)
  • Re: WebService and timeout
    ... If it is going to time out and you need to get your results before you can go any further, calling it asynchronously isn't going to help any. ... I'm dealing with scenario when call to any web method ends up with timeout and I try to add the user a chance to retry ... Everything works fine if timeout doesn't occure. ...
    (microsoft.public.dotnet.languages.csharp)
  • WebService and timeout
    ... I'm dealing with scenario when call to any web method ends up with timeout and I try to add the user a chance to retry ... Everything works fine if timeout doesn't occure. ...
    (microsoft.public.dotnet.framework)
  • WebService and Timeout
    ... I'm dealing with scenario when call to any web method ends up with timeout and I try to add the user a chance to retry ... Everything works fine if timeout doesn't occure. ...
    (microsoft.public.dotnet.general)
  • WebService and Timeout
    ... I'm dealing with scenario when call to any web method ends up with timeout and I try to add the user a chance to retry ... Everything works fine if timeout doesn't occure. ...
    (microsoft.public.dotnet.framework.webservices)