os_cp:find_out_what_is_going_on2
Differences
This shows you the differences between two versions of the page.
| os_cp:find_out_what_is_going_on2 [2024/04/17 21:33] – utworzono jkonczak | os_cp:find_out_what_is_going_on2 [2026/04/27 22:29] (current) – jkonczak | ||
|---|---|---|---|
| Line 22: | Line 22: | ||
| volatile char *const a = data + 64; | volatile char *const a = data + 64; | ||
| volatile char *const b = data + 64 * 2; | volatile char *const b = data + 64 * 2; | ||
| - | atomic_char vA, vB, control; | + | atomic_char vA, vB, barrier; |
| void *th1(void *arg) { | void *th1(void *arg) { | ||
| - | | + | |
| - | while (control | + | while (barrier |
| *b = 1; | *b = 1; | ||
| Line 35: | Line 35: | ||
| void *th2(void *arg) { | void *th2(void *arg) { | ||
| - | | + | |
| - | while (control | + | while (barrier |
| - | + | ||
| - | volatile int dummy = 44; | + | |
| - | while (dummy--); | + | |
| *a = 1; | *a = 1; | ||
| Line 58: | Line 55: | ||
| </ | </ | ||
| < | < | ||
| + | |||
| + | ++++ C++ version of the code | | ||
| + | Compile with: \\ | ||
| + | <code bash>g++ -g -O0 sb.cpp -o sb</ | ||
| + | |||
| + | < | ||
| + | <code cpp sb.cpp> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | volatile char data[64 * 3]; | ||
| + | volatile char &a = data[64]; | ||
| + | volatile char &b = data[64*2]; | ||
| + | std:: | ||
| + | |||
| + | char th1() { | ||
| + | char vA; | ||
| + | |||
| + | barrier++; | ||
| + | while (barrier != 2); | ||
| + | |||
| + | b = 1; | ||
| + | vA = a; | ||
| + | |||
| + | return vA; | ||
| + | } | ||
| + | | ||
| + | char th2() { | ||
| + | char vB; | ||
| + | |||
| + | barrier++; | ||
| + | while (barrier != 2); | ||
| + | |||
| + | a = 1; | ||
| + | vB = b; | ||
| + | |||
| + | return vB; | ||
| + | } | ||
| + | |||
| + | int main() { | ||
| + | auto a1 = std:: | ||
| + | auto a2 = std:: | ||
| + | |||
| + | char vA = a1.get(); | ||
| + | char vB = a2.get(); | ||
| + | |||
| + | printf(" | ||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | < | ||
| + | ++++ | ||
os_cp/find_out_what_is_going_on2.txt · Last modified: by jkonczak