| 1 | #include <pthread.h> |
| 2 | #include <stdio.h> |
| 3 | |
| 4 | enum { iterations = 64 }; |
| 5 | static int total; |
| 6 | |
| 7 | static void *increment(void *unused) |
| 8 | { |
| 9 | (void)unused; |
| 10 | for (int i = 0; i < iterations; ++i) { |
| 11 | __transaction_atomic { |
| 12 | ++total; |
| 13 | } |
| 14 | } |
| 15 | return NULL; |
| 16 | } |
| 17 | |
| 18 | int main(void) |
| 19 | { |
| 20 | pthread_t thread; |
| 21 | if (pthread_create(&thread, NULL, increment, NULL) != 0) |
| 22 | return 1; |
| 23 | increment(NULL); |
| 24 | if (pthread_join(thread, NULL) != 0) |
| 25 | return 1; |
| 26 | printf("transaction total %d\n", total); |
| 27 | return total != 2 * iterations; |
| 28 | } |
| 29 | |