1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #include "test.h"
3 
4 // Test that a linker-initialized mutex can be created/destroyed while in use.
5 
6 // Stub for testing, just invokes annotations.
7 // Meant to be synchronized externally with test barrier.
8 class Mutex {
9  public:
Create(bool linker_initialized=false)10   void Create(bool linker_initialized = false) {
11     if (linker_initialized)
12       ANNOTATE_RWLOCK_CREATE_STATIC(&state_);
13     else
14       ANNOTATE_RWLOCK_CREATE(&state_);
15   }
16 
Destroy()17   void Destroy() {
18     ANNOTATE_RWLOCK_DESTROY(&state_);
19   }
20 
Lock()21   void Lock() {
22     ANNOTATE_RWLOCK_ACQUIRED(&state_, true);
23   }
24 
Unlock()25   void Unlock() {
26     ANNOTATE_RWLOCK_RELEASED(&state_, true);
27   }
28 
29  private:
30   long long state_;
31 };
32 
main()33 int main() {
34   Mutex m;
35 
36   m.Lock();
37   m.Create(true);
38   m.Unlock();
39 
40   m.Lock();
41   m.Destroy();
42   m.Unlock();
43 
44   fprintf(stderr, "DONE\n");
45   return 0;
46 }
47 
48 // CHECK-NOT: WARNING: ThreadSanitizer:
49 // CHECK: DONE
50