PlatformMutex class example - RTOS independent

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 PlatformMutex stdio_mutex;
00004 Thread t2;
00005 Thread t3;
00006     
00007 void notify(const char* name, int state) {
00008     stdio_mutex.lock();
00009     printf("%s: %d\n\r", name, state);
00010     stdio_mutex.unlock();
00011 }
00012 
00013 void test_thread(void const *args) {
00014     while (true) {
00015         notify((const char*)args, 0); wait(1);
00016         notify((const char*)args, 1); wait(1);
00017     }
00018 }
00019 
00020 int main() {
00021     t2.start(callback(test_thread, (void *)"Th 2"));
00022     t3.start(callback(test_thread, (void *)"Th 3"));
00023 
00024     test_thread((void *)"Th 1");
00025 }