finished

Dependencies:   mbed-rtos mbed

Fork of rtos_semaphore by mbed official

Committer:
cathal66
Date:
Fri May 08 10:24:54 2015 +0000
Revision:
4:388272bc6baf
Parent:
1:bdf73f017a77
finished

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:bdf73f017a77 1 #include "mbed.h"
emilmont 1:bdf73f017a77 2 #include "rtos.h"
emilmont 1:bdf73f017a77 3
cathal66 4:388272bc6baf 4 Semaphore two_slots(2); //Setup the use of two semaphores
emilmont 1:bdf73f017a77 5
cathal66 4:388272bc6baf 6 void test_thread(void const *name) { //setup thread function
emilmont 1:bdf73f017a77 7 while (true) {
cathal66 4:388272bc6baf 8 two_slots.wait(); //Wait to get a semaphore to use the
cathal66 4:388272bc6baf 9 printf("%s\n\r", (const char*)name); //when have semaphore printf on serial of thread number
cathal66 4:388272bc6baf 10 Thread::wait(1000); //thread wait
cathal66 4:388272bc6baf 11 two_slots.release(); //Release semaphore back to RTOS
emilmont 1:bdf73f017a77 12 }
emilmont 1:bdf73f017a77 13 }
emilmont 1:bdf73f017a77 14
emilmont 1:bdf73f017a77 15 int main (void) {
cathal66 4:388272bc6baf 16 Thread t2(test_thread, (void *)"Th 2"); //start thread
cathal66 4:388272bc6baf 17 Thread t3(test_thread, (void *)"Th 3"); //start thread
emilmont 1:bdf73f017a77 18
cathal66 4:388272bc6baf 19 test_thread((void *)"Th 1"); //function call in main thread
emilmont 1:bdf73f017a77 20 }