rtos4

Dependencies:   mbed-rtos mbed

Fork of rtos_basic by mbed official

main.cpp

Committer:
xiscosc
Date:
2015-11-13
Revision:
7:68fb4465a2c3
Parent:
3:c92e21f305d8

File content as of revision 7:68fb4465a2c3:

#include "mbed.h"
#include "rtos.h"

Mutex mux;
int a;


void thread1(void const *args) {

    while (true) {
            mux.lock();
            a++;
            printf("LOW %d \r\n",a);
            mux.unlock();
    }
}

void thread2(void const *args) {

    while (true) {
            mux.lock();
            a++;
            printf("HIGH %d \r\n",a);
            mux.unlock();
        }
}

int main() {
    a = 0;
    Thread my_thread1(thread1, NULL, osPriorityLow);
    Thread::wait(10);
    Thread my_thread2(thread2, NULL, osPriorityHigh);

    while (true) {
            printf("MEDIUM \r\n");
        }
}