|
From: <sv...@va...> - 2009-07-21 11:36:53
|
Author: bart
Date: 2009-07-21 12:36:46 +0100 (Tue, 21 Jul 2009)
New Revision: 10501
Log:
- Replaced pthread_cond_wait() by pthread_cond_timedwait() calls.
- An error message is now printed in case pthread_cond_timedwait()
fails.
- Refactoring: joined thread1() and thread2() into one function.
Modified:
trunk/drd/tests/pth_inconsistent_cond_wait.c
trunk/drd/tests/pth_inconsistent_cond_wait.stderr.exp1
trunk/drd/tests/pth_inconsistent_cond_wait.stderr.exp2
Modified: trunk/drd/tests/pth_inconsistent_cond_wait.c
===================================================================
--- trunk/drd/tests/pth_inconsistent_cond_wait.c 2009-07-21 11:19:54 UTC (rev 10500)
+++ trunk/drd/tests/pth_inconsistent_cond_wait.c 2009-07-21 11:36:46 UTC (rev 10501)
@@ -5,8 +5,13 @@
*/
+#include <errno.h> // ETIMEDOUT
#include <pthread.h>
#include <semaphore.h>
+#include <stdio.h>
+#include <string.h> // memset()
+#include <sys/time.h> // gettimeofday()
+#include <time.h> // struct timespec
#include <unistd.h>
pthread_cond_t s_cond;
@@ -14,21 +19,25 @@
pthread_mutex_t s_mutex2;
sem_t s_sem;
-void* thread1(void* arg)
+static void* thread_func(void* mutex)
{
- pthread_mutex_lock(&s_mutex1);
- sem_post(&s_sem);
- pthread_cond_wait(&s_cond, &s_mutex1);
- pthread_mutex_unlock(&s_mutex1);
- return 0;
-}
+ int err;
+ struct timeval now;
+ struct timespec deadline;
-void* thread2(void* arg)
-{
- pthread_mutex_lock(&s_mutex2);
+ pthread_mutex_lock(mutex);
sem_post(&s_sem);
- pthread_cond_wait(&s_cond, &s_mutex2);
- pthread_mutex_unlock(&s_mutex2);
+ gettimeofday(&now, 0);
+ memset(&deadline, 0, sizeof(deadline));
+ deadline.tv_sec = now.tv_sec + 2;
+ deadline.tv_nsec = now.tv_usec * 1000;
+ err = pthread_cond_timedwait(&s_cond, mutex, &deadline);
+ if (err != 0)
+ fprintf(stderr,
+ "pthread_cond_timedwait() call returned error code %d (%s)\n",
+ err,
+ strerror(err));
+ pthread_mutex_unlock(mutex);
return 0;
}
@@ -44,8 +53,8 @@
pthread_mutex_init(&s_mutex2, 0);
/* Create two threads. */
- pthread_create(&tid1, 0, &thread1, 0);
- pthread_create(&tid2, 0, &thread2, 0);
+ pthread_create(&tid1, 0, &thread_func, &s_mutex1);
+ pthread_create(&tid2, 0, &thread_func, &s_mutex2);
/* Wait until both threads have called sem_post(). */
sem_wait(&s_sem);
Modified: trunk/drd/tests/pth_inconsistent_cond_wait.stderr.exp1
===================================================================
--- trunk/drd/tests/pth_inconsistent_cond_wait.stderr.exp1 2009-07-21 11:19:54 UTC (rev 10500)
+++ trunk/drd/tests/pth_inconsistent_cond_wait.stderr.exp1 2009-07-21 11:36:46 UTC (rev 10501)
@@ -1,8 +1,8 @@
Thread 3:
Inconsistent association of condition variable and mutex: condition variable 0x........, mutexes 0x........ and 0x........
- at 0x........: pthread_cond_wait* (drd_pthread_intercepts.c:?)
- by 0x........: thread2 (pth_inconsistent_cond_wait.c:?)
+ at 0x........: pthread_cond_timedwait* (drd_pthread_intercepts.c:?)
+ by 0x........: thread_func (pth_inconsistent_cond_wait.c:?)
by 0x........: vgDrd_thread_wrapper (drd_pthread_intercepts.c:?)
by 0x........: (within libpthread-?.?.so)
by 0x........: clone (in /...libc...)
Modified: trunk/drd/tests/pth_inconsistent_cond_wait.stderr.exp2
===================================================================
--- trunk/drd/tests/pth_inconsistent_cond_wait.stderr.exp2 2009-07-21 11:19:54 UTC (rev 10500)
+++ trunk/drd/tests/pth_inconsistent_cond_wait.stderr.exp2 2009-07-21 11:36:46 UTC (rev 10501)
@@ -1,8 +1,8 @@
Thread 2:
Inconsistent association of condition variable and mutex: condition variable 0x........, mutexes 0x........ and 0x........
- at 0x........: pthread_cond_wait* (drd_pthread_intercepts.c:?)
- by 0x........: thread1 (pth_inconsistent_cond_wait.c:?)
+ at 0x........: pthread_cond_timedwait* (drd_pthread_intercepts.c:?)
+ by 0x........: thread_func (pth_inconsistent_cond_wait.c:?)
by 0x........: vgDrd_thread_wrapper (drd_pthread_intercepts.c:?)
by 0x........: (within libpthread-?.?.so)
by 0x........: clone (in /...libc...)
|