[ORC] Fail materialization in tasks that are destroyed before running.
[llvm-project.git] / compiler-rt / test / sanitizer_common / TestCases / Linux / pthread_mutex.cpp
blobfee88666b2ec05d8f008f4d65b8b8e3063cf6434
1 // RUN: %clangxx -O1 %s -o %t && %run %t
2 // RUN: %clangxx -O1 -DUSE_GLIBC %s -o %t && %run %t
3 // UNSUPPORTED: android
5 #include <pthread.h>
7 #if !defined(__GLIBC_PREREQ)
8 #define __GLIBC_PREREQ(a, b) 0
9 #endif
11 #if defined(USE_GLIBC) && !__GLIBC_PREREQ(2, 34)
12 // They were removed from GLIBC 2.34
13 extern "C" int __pthread_mutex_lock(pthread_mutex_t *__mutex);
14 extern "C" int __pthread_mutex_unlock(pthread_mutex_t *__mutex);
15 #define LOCK __pthread_mutex_lock
16 #define UNLOCK __pthread_mutex_unlock
17 #else
18 #define LOCK pthread_mutex_lock
19 #define UNLOCK pthread_mutex_unlock
20 #endif
22 pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
23 int x;
25 static void *Start(void *arg) {
26 LOCK(&m);
27 ++x;
28 UNLOCK(&m);
29 return nullptr;
32 int main() {
33 pthread_t threads[2] = {};
34 for (pthread_t &t : threads)
35 pthread_create(&t, 0, &Start, 0);
36 for (pthread_t &t : threads)
37 pthread_join(t, 0);
38 return 0;