Case study Embedded System Design
/
Case_Study_rtos_semaphore
finished
Fork of rtos_semaphore by
Diff: main.cpp
- Revision:
- 4:388272bc6baf
- Parent:
- 1:bdf73f017a77
--- a/main.cpp Tue Jun 04 16:05:26 2013 +0100 +++ b/main.cpp Fri May 08 10:24:54 2015 +0000 @@ -1,20 +1,20 @@ #include "mbed.h" #include "rtos.h" -Semaphore two_slots(2); +Semaphore two_slots(2); //Setup the use of two semaphores -void test_thread(void const *name) { +void test_thread(void const *name) { //setup thread function while (true) { - two_slots.wait(); - printf("%s\n\r", (const char*)name); - Thread::wait(1000); - two_slots.release(); + two_slots.wait(); //Wait to get a semaphore to use the + printf("%s\n\r", (const char*)name); //when have semaphore printf on serial of thread number + Thread::wait(1000); //thread wait + two_slots.release(); //Release semaphore back to RTOS } } int main (void) { - Thread t2(test_thread, (void *)"Th 2"); - Thread t3(test_thread, (void *)"Th 3"); + Thread t2(test_thread, (void *)"Th 2"); //start thread + Thread t3(test_thread, (void *)"Th 3"); //start thread - test_thread((void *)"Th 1"); + test_thread((void *)"Th 1"); //function call in main thread }