int i;
int ret;
- for (i = 0; i < 10; i++) {
+ for (i = 0; i < 7; i++) {
printf("Thread %d, loop %d\n", thrd_current(), i);
- switch (i % 4) {
+ switch (i ) {
case 1:
ret = atomic_load(obj);
printf("Read value: %d\n", ret);
break;
- case 3:
+ case 0:
atomic_store(obj, i);
printf("Write value: %d\n", i);
break;
thrd_t t1, t2;
atomic_int obj;
- printf("Creating 2 threads\n");
+ atomic_init(&obj, 0);
+
+ printf("Thread %d: creating 2 threads\n", thrd_current());
thrd_create(&t1, (thrd_start_t)&a, &obj);
thrd_create(&t2, (thrd_start_t)&a, &obj);
thrd_join(t1);
thrd_join(t2);
- printf("Thread is finished\n");
+ printf("Thread %d is finished\n", thrd_current());
}