int i;
for (i = 0; i < 10; i++) {
- printf("Thread %d, loop %d\n", thread_current()->id, i);
- if (i % 2)
+ printf("Thread %d, loop %d\n", thrd_current(), i);
+ switch (i % 4) {
+ case 1:
atomic_load(obj);
+ break;
+ case 3:
+ atomic_store(obj, i);
+ break;
+ }
}
}
void user_main()
{
- struct thread t1, t2;
+ thrd_t t1, t2;
atomic_int obj;
- printf("%s() creating 2 threads\n", __func__);
- thread_create(&t1, &a, &obj);
- thread_create(&t2, &a, &obj);
+ printf("Creating 2 threads\n");
+ thrd_create(&t1, (thrd_start_t)&a, &obj);
+ thrd_create(&t2, (thrd_start_t)&a, &obj);
- thread_join(&t1);
- thread_join(&t2);
- printf("%s() is finished\n", __func__);
+ thrd_join(t1);
+ thrd_join(t2);
+ printf("Thread is finished\n");
}