ok

Dependencies:   mbed-rtos mbed

Fork of rtos_mutex by mbed official

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 Mutex stdio_mutex; 
00005 
00006 void notify(const char* name, int state) {
00007     stdio_mutex.lock();
00008     printf("%s: %d\n\r", name, state);
00009     stdio_mutex.unlock();
00010 }
00011 
00012 void test_thread(void const *args) {
00013     while (true) {
00014         notify((const char*)args, 0); Thread::wait(1000);
00015         notify((const char*)args, 1); Thread::wait(1000);
00016     }
00017 }
00018 
00019 int main() {
00020     Thread t2(test_thread, (void *)"Th 2");
00021     Thread t3(test_thread, (void *)"Th 3");
00022     
00023     test_thread((void *)"Th 1");
00024 }