get localeconv into the linklib
[cake.git] / test / threads / mutex.c
blob55b843eebc4d2ebe21e1270ee6d68fc575a5224c
1 #include <libraries/thread.h>
2 #include <proto/thread.h>
3 #include <proto/dos.h>
4 #include <stdio.h>
5 #include <stdint.h>
7 void *locker_thread(void *data) {
8 void *mutex = data;
9 uint32_t id = CurrentThread();
11 printf("[%d] starting, locking the mutex\n", id);
12 LockMutex(mutex);
14 printf("[%d] got it, pausing for 5s\n", id);
15 Delay(250);
17 printf("[%d] unlocking the mutex\n", id);
18 UnlockMutex(mutex);
20 printf("[%d] all done, exiting\n", id);
22 return NULL;
25 void *waiter_thread(void *data) {
26 void *mutex = data;
27 uint32_t id = CurrentThread();
29 printf("[%d] starting, locking the mutex\n", id);
30 LockMutex(mutex);
32 printf("[%d] got it, unlocking\n", id);
33 UnlockMutex(mutex);
35 printf("[%d] all done, exiting\n", id);
37 return NULL;
40 int main (int argc, char **argv) {
41 void *mutex;
42 uint32_t tl, tw;
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");
51 Delay(100);
53 printf("starting waiter thread\n");
54 tw = CreateThread(waiter_thread, (void *) mutex);
56 printf("waiting for locker thread to exit\n");
57 WaitThread(tl, NULL);
59 printf("waiting for waiter thread to exit\n");
60 WaitThread(tw, NULL);
62 printf("destroying the mutex\n");
63 DestroyMutex(mutex);
65 printf("all done\n");
67 return 0;