12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #include <threads.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <support/check.h>
- static mtx_t mutex;
- static int counter;
- static int
- child_add (void *arg)
- {
- if (mtx_lock (&mutex) != thrd_success)
- FAIL_EXIT1 ("mtx_lock failed");
- counter++;
- if (mtx_unlock (&mutex) != thrd_success)
- FAIL_EXIT1 ("mtx_unlock failed");
- thrd_exit (thrd_success);
- }
- static int
- do_test (void)
- {
- mtx_init (&mutex, mtx_plain);
- thrd_t id;
- if (thrd_create (&id, child_add, NULL) != thrd_success)
- FAIL_EXIT1 ("thrd_create failed");
- if (mtx_lock (&mutex) != thrd_success)
- FAIL_EXIT1 ("mtx_lock failed");
- counter++;
- if (mtx_unlock (&mutex) != thrd_success)
- FAIL_EXIT1 ("mtx_unlock failed");
- if (thrd_join (id, NULL) != thrd_success)
- FAIL_EXIT1 ("thrd_join failed");
- if (counter != 2)
- FAIL_EXIT1 ("counter (%d) != 2", counter);
- mtx_destroy (&mutex);
- return 0;
- }
- #include <support/test-driver.c>
|