| 1 |
// Test pthread_cond_clockwait not generating false positives with tsan |
| 2 |
// { dg-do run { target { { *-*-linux* *-*-gnu* *-*-uclinux* } && pthread } } } |
| 3 |
// { dg-options "-fsanitize=thread -lpthread" } |
| 4 |
|
| 5 |
#include <pthread.h> |
| 6 |
|
| 7 |
// This overloaded version should only be selected on targets that |
| 8 |
// don't have a pthread_cond_clockwait in pthread.h, and it will wait |
| 9 |
// indefinitely for the cond_signal that, in this testcase, ought to |
| 10 |
// be delivered. |
| 11 |
static inline int |
| 12 |
pthread_cond_clockwait (pthread_cond_t *cv, |
| 13 |
pthread_mutex_t *mtx, |
| 14 |
__clockid_t, |
| 15 |
void const /* struct timespec */ *) |
| 16 |
{ |
| 17 |
return pthread_cond_wait (cv, mtx); |
| 18 |
} |
| 19 |
|
| 20 |
pthread_cond_t cv; |
| 21 |
pthread_mutex_t mtx; |
| 22 |
|
| 23 |
void *fn(void *vp) { |
| 24 |
pthread_mutex_lock(&mtx); |
| 25 |
pthread_cond_signal(&cv); |
| 26 |
pthread_mutex_unlock(&mtx); |
| 27 |
return NULL; |
| 28 |
} |
| 29 |
|
| 30 |
int main() { |
| 31 |
pthread_mutex_lock(&mtx); |
| 32 |
|
| 33 |
pthread_t tid; |
| 34 |
pthread_create(&tid, NULL, fn, NULL); |
| 35 |
|
| 36 |
struct timespec ts; |
| 37 |
clock_gettime(CLOCK_MONOTONIC, &ts); |
| 38 |
ts.tv_sec += 10; |
| 39 |
pthread_cond_clockwait(&cv, &mtx, CLOCK_MONOTONIC, &ts); |
| 40 |
pthread_mutex_unlock(&mtx); |
| 41 |
|
| 42 |
pthread_join(tid, NULL); |
| 43 |
return 0; |
| 44 |
} |