/
simple_nested_No_AV.cpp
55 lines (42 loc) · 1.11 KB
/
simple_nested_No_AV.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "t_debug_task.h"
#include "tbb/mutex.h"
#include<iostream>
using namespace std;
using namespace tbb;
tbb::mutex x_mutex;
tbb::mutex::scoped_lock myLock;
int CHECK_AV x = 0;
class SimpleAV: public t_debug_task {
public:
task* execute() {
__exec_begin__(getTaskId());
// READ & WRITE
CaptureLockAcquire(get_cur_tid(), (ADDRINT)&x_mutex);
myLock.acquire(x_mutex);
x++;
// READ
if (x == 1) {
CaptureLockRelease(get_cur_tid());
myLock.release();
set_ref_count(3);
task& a = *new(allocate_child()) SimpleAV();
spawn(a);
task& b = *new(allocate_child()) SimpleAV();
spawn_and_wait_for_all(b);
} else {
CaptureLockRelease(get_cur_tid());
myLock.release();
}
__exec_end__(getTaskId());
return NULL;
}
};
int main( int argc, const char *argv[] ) {
TD_Activate();
task& a = *new(task::allocate_root()) SimpleAV();
t_debug_task::spawn(a);
task& b = *new(task::allocate_root()) SimpleAV();
t_debug_task::spawn_root_and_wait(b);
cout << "x " << (size_t)&x << " is " << x << std::endl;
Fini();
}