1 #include <libraries/thread.h>
2 #include <proto/thread.h>
7 void *locker_thread(void *data
) {
9 uint32_t id
= CurrentThread();
11 printf("[%d] starting, locking the mutex\n", id
);
14 printf("[%d] got it, pausing for 5s\n", id
);
17 printf("[%d] unlocking the mutex\n", id
);
20 printf("[%d] all done, exiting\n", id
);
25 void *waiter_thread(void *data
) {
27 uint32_t id
= CurrentThread();
29 printf("[%d] starting, locking the mutex\n", id
);
32 printf("[%d] got it, unlocking\n", id
);
35 printf("[%d] all done, exiting\n", id
);
40 int main (int argc
, char **argv
) {
44 printf("creating mutex\n");
45 mutex
= CreateMutex();
47 printf("starting locker thread\n");
48 tl
= CreateThread(locker_thread
, (void *) mutex
);
50 printf("sleeping for 2s\n");
53 printf("starting waiter thread\n");
54 tw
= CreateThread(waiter_thread
, (void *) mutex
);
56 printf("waiting for locker thread to exit\n");
59 printf("waiting for waiter thread to exit\n");
62 printf("destroying the mutex\n");