semaphore example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

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