diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-02-10 07:45:43 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-02-10 07:45:43 +0000 |
commit | 476c4db3dc56bee43df384704c75ccc71cfa7a1d (patch) | |
tree | 5d0dcec3cc12fc53532fc84029892b98711a2596 /test/tsan/load_shared_lib.cc | |
parent | ca9211ecdede9bdedb812b2243a4abdb8dacd1b9 (diff) |
Notes
Diffstat (limited to 'test/tsan/load_shared_lib.cc')
-rw-r--r-- | test/tsan/load_shared_lib.cc | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/test/tsan/load_shared_lib.cc b/test/tsan/load_shared_lib.cc index a27dc1cc6ffb6..b7934b82df73a 100644 --- a/test/tsan/load_shared_lib.cc +++ b/test/tsan/load_shared_lib.cc @@ -7,35 +7,39 @@ #ifdef BUILD_SO -#include <stddef.h> -#include <unistd.h> +#include "test.h" int GLOB_SHARED = 0; extern "C" +void init_so() { + barrier_init(&barrier, 2); +} + +extern "C" void *write_from_so(void *unused) { - if (unused) - sleep(1); + if (unused == 0) + barrier_wait(&barrier); GLOB_SHARED++; + if (unused != 0) + barrier_wait(&barrier); return NULL; } #else // BUILD_SO +#include "test.h" #include <dlfcn.h> -#include <pthread.h> -#include <stdio.h> -#include <stddef.h> -#include <unistd.h> - #include <string> int GLOB = 0; void *write_glob(void *unused) { - if (unused) - sleep(1); + if (unused == 0) + barrier_wait(&barrier); GLOB++; + if (unused != 0) + barrier_wait(&barrier); return NULL; } @@ -48,6 +52,7 @@ void race_two_threads(void *(*access_callback)(void *unused)) { } int main(int argc, char *argv[]) { + barrier_init(&barrier, 2); std::string path = std::string(argv[0]) + std::string("-so.so"); race_two_threads(write_glob); // CHECK: write_glob @@ -56,6 +61,9 @@ int main(int argc, char *argv[]) { printf("error in dlopen(): %s\n", dlerror()); return 1; } + void (*init_so)(); + *(void **)&init_so = dlsym(lib, "init_so"); + init_so(); void *(*write_from_so)(void *unused); *(void **)&write_from_so = dlsym(lib, "write_from_so"); race_two_threads(write_from_so); |