WARNING: ThreadSanitizer: data race (pid=14924)
Write of size 1 at 0x000001533808 by main thread:
#0 pthread_barrier_destroy /home/rfp/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:1236 (barrier-2+0x00000042ed1b)
#1 main /home/rfp/src/tsan.tests/barrier-2.cc:28:9 (barrier-2+0x0000004a93ad)
Previous read of size 1 at 0x000001533808 by thread T1:
#0 pthread_barrier_wait /home/rfp/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:1243 (barrier-2+0x00000043e14e)
#1 f(void*) /home/rfp/src/tsan.tests/barrier-2.cc:9:9 (barrier-2+0x0000004a91ae)
Location is global 'b' of size 32 at 0x000001533808 (barrier-2+0x000001533808)
Thread T1 (tid=14926, finished) created by main thread at:
#0 pthread_create /home/rfp/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:848 (barrier-2+0x0000004478d3)
#1 main /home/rfp/src/tsan.tests/barrier-2.cc:21:9 (barrier-2+0x0000004a92d3)
SUMMARY: ThreadSanitizer: data race /home/rfp/src/tsan.tests/barrier-2.cc:28:9 in main
#include <stdio.h>
#include <assert.h>
#include <pthread.h>
pthread_barrier_t b;
void *f(void *arg) {
int r;
r = pthread_barrier_wait(&b);
fprintf(stderr, "%s %u %d\n", __FUNCTION__, __LINE__, r);
assert(r == 0 || r == PTHREAD_BARRIER_SERIAL_THREAD);
return arg;
}
int main(void) {
int r;
r = pthread_barrier_init(&b, nullptr, 2);
assert(r == 0);
pthread_t id;
r = pthread_create(&id, nullptr, f, nullptr);
assert(r == 0);
r = pthread_barrier_wait(&b);
fprintf(stderr, "%s %u %d\n", __FUNCTION__, __LINE__, r);
assert(r == 0 || r == PTHREAD_BARRIER_SERIAL_THREAD);
r = pthread_barrier_destroy(&b);
assert(r == 0);
void *retptr;
r = pthread_join(id, &retptr);
assert(r == 0);
return 0;
}
--
You received this message because you are subscribed to the Google Groups "thread-sanitizer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thread-sanitiz...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
But pthread_barrier_wait will not return to any of the threads until the barrier has been entered by all of the threads. So, why is this an app problem?
If I call sleep(10) on the main thread between the barrier_wait and the barrier_destroy, there is still a race reported. In this case, it is obvious that both threads have exited the barrier.
The printf's fire before the sleep is called. Therefore, all threads are out of the barrier before barrier destroy is called.