1 #include <exec/memory.h>
2 #include <libraries/thread.h>
3 #include <proto/exec.h>
5 #include <proto/thread.h>
14 void *waiter_thread(void *data
) {
15 struct thread_data
*td
= (struct thread_data
*) data
;
16 uint32_t id
= CurrentThread();
18 printf("[%d] starting, locking the mutex\n", id
);
21 printf("[%d] waiting on the condition\n", id
);
22 WaitCondition(td
->cond
, td
->mutex
);
24 printf("[%d] condition signalled, unlocking the mutex\n", id
);
25 UnlockMutex(td
->mutex
);
27 printf("[%d] all done, exiting\n", id
);
32 int main (int argc
, char **argv
) {
33 struct thread_data
*td
;
36 td
= AllocMem(sizeof(struct thread_data
), MEMF_PUBLIC
| MEMF_CLEAR
);
38 printf("creating mutex\n");
39 td
->mutex
= CreateMutex();
41 printf("creating condition\n");
42 td
->cond
= CreateCondition();
44 printf("starting waiter thread\n");
45 tw
= CreateThread(waiter_thread
, (void *) td
);
47 printf("sleeping for 2s\n");
50 printf("signalling condition\n");
51 SignalCondition(td
->cond
);
53 printf("waiting for waiter thread\n");
56 printf("destroying the condition\n");
57 DestroyCondition(td
->cond
);
59 printf("destroying the mutex\n");
60 DestroyMutex(td
->mutex
);
62 FreeMem(td
, sizeof(struct thread_data
));