1 // RUN: %clangxx -O1 %s -o %t && %run %t 2 // RUN: %clangxx -O1 -DUSE_GLIBC %s -o %t && %run %t 3 // UNSUPPORTED: android 4 5 #include <pthread.h> 6 7 #ifdef USE_GLIBC 8 extern "C" int __pthread_mutex_lock(pthread_mutex_t *__mutex); 9 extern "C" int __pthread_mutex_unlock(pthread_mutex_t *__mutex); 10 #define LOCK __pthread_mutex_lock 11 #define UNLOCK __pthread_mutex_unlock 12 #else 13 #define LOCK pthread_mutex_lock 14 #define UNLOCK pthread_mutex_unlock 15 #endif 16 17 pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; 18 int x; 19 Start(void * arg)20static void *Start(void *arg) { 21 LOCK(&m); 22 ++x; 23 UNLOCK(&m); 24 return nullptr; 25 } 26 main()27int main() { 28 pthread_t threads[2] = {}; 29 for (pthread_t &t : threads) 30 pthread_create(&t, 0, &Start, 0); 31 for (pthread_t &t : threads) 32 pthread_join(t, 0); 33 return 0; 34 } 35