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