• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "test_utils.h"
2 Mutex mu1;  // This Mutex guards var.
3 Mutex mu2;  // This Mutex is not related to var.
4 int   var;  // GUARDED_BY(mu1)
5 
Thread1()6 void Thread1() {  // Runs in thread named 'test-thread-1'.
7   MutexLock lock(&mu1);  // Correct Mutex.
8   var = 1;
9 }
10 
Thread2()11 void Thread2() {  // Runs in thread named 'test-thread-2'.
12   MutexLock lock(&mu2);  // Wrong Mutex.
13   var = 2;
14 }
15 
main()16 int main() {
17   ANNOTATE_TRACE_MEMORY(&var);
18   var = 0;
19   MyThread t1(Thread1, NULL, "test-thread-1");
20   MyThread t2(Thread2, NULL, "test-thread-2");
21   t1.Start();
22   t2.Start();
23   t1.Join();
24   t2.Join();
25 }
26