30 lines · cpp
1// RUN: %clang_cc1 %s -Wthread-safety-analysis -verify -fexceptions2// expected-no-diagnostics3 4class Mutex {5public:6 void Lock() __attribute__((exclusive_lock_function()));7 void Unlock() __attribute__((unlock_function()));8};9 10class A {11public:12 Mutex mu1, mu2;13 14 void foo() __attribute__((exclusive_locks_required(mu1))) __attribute__((exclusive_locks_required(mu2))) {}15 16 template <class T>17 void bar() __attribute__((exclusive_locks_required(mu1))) __attribute__((exclusive_locks_required(mu2))) {18 foo();19 }20};21 22void f() {23 A a;24 a.mu1.Lock();25 a.mu2.Lock();26 a.bar<int>();27 a.mu2.Unlock();28 a.mu1.Unlock();29}30