István Cserny / Mbed 2 deprecated Lab07_RTOS_mutex

Dependencies:   mbed mbed-rtos

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