mbed official
/
rtos_semaphore
Basic example showing the Semaphore API
Embed:
(wiki syntax)
Show/hide line numbers
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 }
Generated on Tue Jul 12 2022 11:27:36 by 1.7.2