MCPcopy Create free account
hub / github.com/acl-dev/acl / main

Function main

lib_acl_cpp/samples/atomic/main.cpp:79–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79int main(void)
80{
81 test();
82 acl::atomic_long_test test;
83 test.run();
84
85 //////////////////////////////////////////////////////////////////////
86
87 printf("-------------------------------------------------------\r\n");
88
89 long long n;
90 acl::atomic_long count(0);
91
92 n = count.fetch_add(100);
93 printf(">>n: %lld\r\n", n);
94
95 n = count.add_fetch(200);
96 printf(">>n: %lld\r\n", n);
97
98 std::vector<acl::thread*> threads;
99 int max = 1000000;
100
101 struct timeval begin, end;
102 gettimeofday(&begin, NULL);
103
104 for (int i = 0; i < 20; i++) {
105 acl::thread* thr = new mythread(count, max);
106 thr->set_detachable(false);
107 threads.push_back(thr);
108 thr->start();
109 }
110
111 for (std::vector<acl::thread*>::iterator it = threads.begin();
112 it != threads.end(); ++it) {
113 (*it)->wait();
114 delete *it;
115 }
116
117 gettimeofday(&end, NULL);
118
119 n = count--;
120 count += 100;
121
122 if (100 < count && count >= 1)
123 printf(">>n: %lld, %lld, spent: %.2f\r\n",
124 count.value(), n, stamp_sub(&end, &begin));
125
126 //////////////////////////////////////////////////////////////////////
127
128 acl::locker lock;
129 n = 0;
130
131 threads.clear();
132
133 for (int i = 0; i < 20; i++) {
134 acl::thread* thr = new mythread2(lock, n, max);
135 thr->set_detachable(false);
136 threads.push_back(thr);

Callers

nothing calls this directly

Calls 13

fetch_addMethod · 0.80
add_fetchMethod · 0.80
beginMethod · 0.80
testFunction · 0.70
stamp_subFunction · 0.70
gettimeofdayFunction · 0.50
runMethod · 0.45
push_backMethod · 0.45
startMethod · 0.45
endMethod · 0.45
waitMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…