Lee Nam Cheol / Mbed OS lab06-mutex-yes
Committer:
namcheol
Date:
Mon May 18 12:25:57 2020 +0000
Revision:
3:1c8ab6d6af18
Parent:
2:20e20cfae75e
lab06-mutex-yes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dshin 0:f31836d48420 1 #include "mbed.h"
dshin 0:f31836d48420 2
namcheol 3:1c8ab6d6af18 3 Serial pc(USBTX, USBRX, 115200);
namcheol 3:1c8ab6d6af18 4 Thread thread1, thread2, thread3;
namcheol 3:1c8ab6d6af18 5 Mutex mutex;
namcheol 3:1c8ab6d6af18 6
namcheol 3:1c8ab6d6af18 7
namcheol 3:1c8ab6d6af18 8 void thread_1()
namcheol 3:1c8ab6d6af18 9 {
namcheol 3:1c8ab6d6af18 10 while(true) {
namcheol 3:1c8ab6d6af18 11 mutex.lock();
namcheol 3:1c8ab6d6af18 12 for(int i = 0; i<50; i++)
namcheol 3:1c8ab6d6af18 13 printf("1");
namcheol 3:1c8ab6d6af18 14 printf("\r\n");
namcheol 3:1c8ab6d6af18 15 mutex.unlock();
namcheol 3:1c8ab6d6af18 16 }
namcheol 3:1c8ab6d6af18 17 }
namcheol 3:1c8ab6d6af18 18
namcheol 3:1c8ab6d6af18 19 void thread_2()
namcheol 3:1c8ab6d6af18 20 {
namcheol 3:1c8ab6d6af18 21 while(true) {
namcheol 3:1c8ab6d6af18 22 mutex.lock();
namcheol 3:1c8ab6d6af18 23 for(int i = 0; i<50; i++)
namcheol 3:1c8ab6d6af18 24 printf("2");
namcheol 3:1c8ab6d6af18 25 printf("\r\n");
namcheol 3:1c8ab6d6af18 26 mutex.unlock();
namcheol 3:1c8ab6d6af18 27 }
namcheol 3:1c8ab6d6af18 28 }
namcheol 3:1c8ab6d6af18 29
namcheol 3:1c8ab6d6af18 30 void thread_3()
namcheol 3:1c8ab6d6af18 31 {
namcheol 3:1c8ab6d6af18 32 while(true) {
namcheol 3:1c8ab6d6af18 33 mutex.lock();
namcheol 3:1c8ab6d6af18 34 for(int i = 0; i<50; i++)
namcheol 3:1c8ab6d6af18 35 printf("3");
namcheol 3:1c8ab6d6af18 36 printf("\r\n");
namcheol 3:1c8ab6d6af18 37 mutex.unlock();
namcheol 3:1c8ab6d6af18 38 }
namcheol 3:1c8ab6d6af18 39 }
dshin 0:f31836d48420 40
dshin 0:f31836d48420 41 int main()
dshin 0:f31836d48420 42 {
namcheol 3:1c8ab6d6af18 43 thread1.start(thread_1);
namcheol 3:1c8ab6d6af18 44 thread2.start(thread_2);
namcheol 3:1c8ab6d6af18 45 thread3.start(thread_3);
namcheol 3:1c8ab6d6af18 46
namcheol 3:1c8ab6d6af18 47 while(true);
dshin 0:f31836d48420 48 }