István Cserny / Mbed 2 deprecated Lab07_RTOS_mutex

Dependencies:   mbed mbed-rtos

Revision:
0:fe1656248d2b
diff -r 000000000000 -r fe1656248d2b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Feb 24 08:06:02 2022 +0000
@@ -0,0 +1,30 @@
+#include "mbed.h"
+#include "rtos.h"
+
+Serial pc(USBTX,USBRX);     //UART via ST-Link
+Mutex stdio_mutex;
+
+void notify(const char* name, int state)
+{
+    stdio_mutex.lock();
+    pc.printf("%s: %d\n\r", name, state);
+    stdio_mutex.unlock();
+}
+
+void test_thread(void const *args)
+{
+    while (true) {
+        notify((const char*)args, 0);
+        Thread::wait(1000);
+        notify((const char*)args, 1);
+        Thread::wait(1000);
+    }
+}
+
+int main()
+{
+    pc.baud(115200);
+    Thread t2(test_thread, (void *)"Th 2");
+    Thread t3(test_thread, (void *)"Th 3");
+    test_thread((void *)"Th 1");
+}
\ No newline at end of file