Lee Nam Cheol / Mbed OS lab06-mutex-yes

main.cpp

Committer:
namcheol
Date:
2020-05-18
Revision:
3:1c8ab6d6af18
Parent:
2:20e20cfae75e

File content as of revision 3:1c8ab6d6af18:

#include "mbed.h"

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()
{
    thread1.start(thread_1);
    thread2.start(thread_2);
    thread3.start(thread_3);
    
    while(true);
}