Lee Nam Cheol / Mbed OS lab06-mutex-yes

Files at this revision

API Documentation at this revision

Comitter:
namcheol
Date:
Mon May 18 12:25:57 2020 +0000
Parent:
2:20e20cfae75e
Commit message:
lab06-mutex-yes

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Apr 27 08:02:20 2020 +0000
+++ b/main.cpp	Mon May 18 12:25:57 2020 +0000
@@ -1,14 +1,48 @@
 #include "mbed.h"
 
-Serial uart_tx(D1, D0);   //D1 = tx, D0 = rx
-DigitalIn sw(D2, PullDown);
+Serial pc(USBTX, USBRX, 115200);
+Thread thread1, thread2, thread3;
+Mutex mutex;
+
+
+void thread_1()
+{
+    while(true) {
+        mutex.lock();
+        for(int i = 0; i<50; i++)
+            printf("1");
+        printf("\r\n");
+        mutex.unlock();
+    }
+}
+
+void thread_2()
+{
+    while(true) {
+        mutex.lock();
+        for(int i = 0; i<50; i++)
+            printf("2");
+        printf("\r\n");
+        mutex.unlock();
+    }
+}
+
+void thread_3()
+{
+    while(true) {
+        mutex.lock();
+        for(int i = 0; i<50; i++)
+            printf("3");
+        printf("\r\n");
+        mutex.unlock();
+    }
+}
 
 int main()
 {
-    while(true) {
-        if(sw == 1) {
-            uart_tx.putc('1');
-            thread_sleep_for(200);
-        }
-    }
+    thread1.start(thread_1);
+    thread2.start(thread_2);
+    thread3.start(thread_3);
+    
+    while(true);
 }
\ No newline at end of file