| 77 | } |
| 78 | |
| 79 | int 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); |
nothing calls this directly
no test coverage detected
searching dependent graphs…