Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 3:1c8ab6d6af18, committed 2020-05-18
- 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