Just change the NUMREADERS macro to add more reader-threads.
Having 3 or more threads is a more interesting example, since there's
no contention if you just have one thread spin, waiting for the other.
printf("var = %d\n", load_32(&var));
}
printf("var = %d\n", load_32(&var));
}
int user_main(int argc, char **argv)
{
int user_main(int argc, char **argv)
{
+ thrd_t A, B[NUMREADERS];
+ int i;
- barr = new spinning_barrier(2);
+ barr = new spinning_barrier(NUMREADERS + 1);
- thrd_create(&t2, &threadA, NULL);
- thrd_create(&t3, &threadB, NULL);
- thrd_join(t2);
- thrd_join(t3);
+ thrd_create(&A, &threadA, NULL);
+ for (i = 0; i < NUMREADERS; i++)
+ thrd_create(&B[i], &threadB, NULL);
+
+ for (i = 0; i < NUMREADERS; i++)
+ thrd_join(B[i]);
+ thrd_join(A);