vinix-ports / tests / toolchain / transaction.c
28 lines · 25 sloc · 555 bytes · e9d38658eac1f6ccabeafd3cc560020b098402c7
Raw
1#include <pthread.h>
2#include <stdio.h>
3
4enum { iterations = 64 };
5static int total;
6
7static 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
18int 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