ok

Dependencies:   mbed-rtos mbed

Fork of rtos_mutex by mbed official

Committer:
avnisha
Date:
Thu Aug 15 06:50:18 2013 +0000
Revision:
5:6db3dda5dea5
Parent:
1:0f886ffbe0c1
ok

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:0f886ffbe0c1 1 #include "mbed.h"
emilmont 1:0f886ffbe0c1 2 #include "rtos.h"
emilmont 1:0f886ffbe0c1 3
emilmont 1:0f886ffbe0c1 4 Mutex stdio_mutex;
emilmont 1:0f886ffbe0c1 5
emilmont 1:0f886ffbe0c1 6 void notify(const char* name, int state) {
emilmont 1:0f886ffbe0c1 7 stdio_mutex.lock();
emilmont 1:0f886ffbe0c1 8 printf("%s: %d\n\r", name, state);
emilmont 1:0f886ffbe0c1 9 stdio_mutex.unlock();
emilmont 1:0f886ffbe0c1 10 }
emilmont 1:0f886ffbe0c1 11
emilmont 1:0f886ffbe0c1 12 void test_thread(void const *args) {
emilmont 1:0f886ffbe0c1 13 while (true) {
emilmont 1:0f886ffbe0c1 14 notify((const char*)args, 0); Thread::wait(1000);
emilmont 1:0f886ffbe0c1 15 notify((const char*)args, 1); Thread::wait(1000);
emilmont 1:0f886ffbe0c1 16 }
emilmont 1:0f886ffbe0c1 17 }
emilmont 1:0f886ffbe0c1 18
emilmont 1:0f886ffbe0c1 19 int main() {
emilmont 1:0f886ffbe0c1 20 Thread t2(test_thread, (void *)"Th 2");
emilmont 1:0f886ffbe0c1 21 Thread t3(test_thread, (void *)"Th 3");
emilmont 1:0f886ffbe0c1 22
emilmont 1:0f886ffbe0c1 23 test_thread((void *)"Th 1");
emilmont 1:0f886ffbe0c1 24 }