-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_uint8.cpp
More file actions
33 lines (32 loc) · 749 Bytes
/
Copy pathtest_uint8.cpp
File metadata and controls
33 lines (32 loc) · 749 Bytes
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
#include <algorithm>
#include <atomic>
#include <memory.h>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <ctime>
#include <unistd.h>
#include <cilk/cilk.h>
#include <cilk/cilk_api.h>
using namespace std;
void atomic_add(atomic<uint8_t> &a, uint8_t b) {
auto current = a.load();
while (!a.compare_exchange_weak(current, current + b));
;
}
uint8_t Atomic_add(atomic<uint8_t> &a, uint8_t b) {
while (1) {
auto current = a.load();
if (a.compare_exchange_weak(current, current + b)) {
return current;
}
}
}
int main() {
//uint8_t a = 0;
atomic<uint8_t> a(0);
for (int i = 0; i < 600; i ++) {
printf("%d ",Atomic_add(a, 1) );
}
cout << endl;
}