Basic example showing the Semaphore API

Dependencies:   mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 
00004 Semaphore two_slots(2);
00005 
00006 void test_thread(void const *name) {
00007     while (true) {
00008         two_slots.wait();
00009         printf("%s\n\r", (const char*)name);
00010         Thread::wait(1000);
00011         two_slots.release();
00012     }
00013 }
00014 
00015 int main (void) {
00016     Thread t2;
00017     Thread t3;
00018 
00019     t2.start(callback(test_thread, (void *)"Th 2"));
00020     t3.start(callback(test_thread, (void *)"Th 3"));
00021 
00022     test_thread((void *)"Th 1");
00023 }