40 lines · cpp
1// RUN: %clangxx -O1 %s -o %t && %run %t2// RUN: %clangxx -O1 -DUSE_GLIBC %s -o %t && %run %t3// UNSUPPORTED: android4 5#include <pthread.h>6 7#if !defined(__GLIBC_PREREQ)8#define __GLIBC_PREREQ(a, b) 09#endif10 11#if defined(USE_GLIBC) && !__GLIBC_PREREQ(2, 34)12// They were removed from GLIBC 2.3413extern "C" int __pthread_mutex_lock(pthread_mutex_t *__mutex);14extern "C" int __pthread_mutex_unlock(pthread_mutex_t *__mutex);15#define LOCK __pthread_mutex_lock16#define UNLOCK __pthread_mutex_unlock17#else18#define LOCK pthread_mutex_lock19#define UNLOCK pthread_mutex_unlock20#endif21 22pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;23int x;24 25static void *Start(void *arg) {26 LOCK(&m);27 ++x;28 UNLOCK(&m);29 return nullptr;30}31 32int 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;39}40