semaphore example

main.cpp

Committer:
mab5449
Date:
2017-01-13
Revision:
5:574f47121e8e
Parent:
4:ec4791bc6554
Child:
7:755dee0042c3

File content as of revision 5:574f47121e8e:

#include "mbed.h"

Semaphore two_slots(2);
Thread t2;
Thread t3;
    
void test_thread(void const *name) {
    while (true) {
        two_slots.wait();
        printf("%s\n\r", (const char*)name);
        wait(1);
        two_slots.release();
    }
}

int main (void) {
    t2.start(callback(test_thread, (void *)"Th 2"));
    t3.start(callback(test_thread, (void *)"Th 3"));

    test_thread((void *)"Th 1");
}