William Singleton / Mbed 2 deprecated 595_Lab_8_Part_III_Semaphore

Dependencies:   mbed mbed-rtos

Files at this revision

API Documentation at this revision

Comitter:
wssingle
Date:
Sun May 03 19:12:28 2020 +0000
Parent:
12:4e3f46e615d9
Commit message:
Lab 8 part 3

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Mar 30 18:54:14 2020 +0000
+++ b/main.cpp	Sun May 03 19:12:28 2020 +0000
@@ -0,0 +1,23 @@
+#include "mbed.h"
+#include "rtos.h"
+ 
+Semaphore two_slots(2);
+ 
+void test_thread(void const *name) {
+    while (true) {
+        two_slots.wait();
+        printf("%s\n\r", (const char*)name);
+        Thread::wait(1000);
+        two_slots.release();
+    }
+}
+ 
+int main (void) {
+    Thread t2;
+    Thread t3;
+ 
+    t2.start(callback(test_thread, (void *)"Th 2"));
+    t3.start(callback(test_thread, (void *)"Th 3"));
+ 
+    test_thread((void *)"Th 1");
+}
\ No newline at end of file