fdasfasd

Dependencies:   mbed-rtos mbed

Fork of rtos_mutex by mbed official

Committer:
MaxAigner
Date:
Sun Jan 18 14:19:44 2015 +0000
Revision:
5:c1722555cc45
Parent:
1:0f886ffbe0c1
test

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"
MaxAigner 5:c1722555cc45 3 #include <string>
MaxAigner 5:c1722555cc45 4 #include "iostream"
emilmont 1:0f886ffbe0c1 5
emilmont 1:0f886ffbe0c1 6 Mutex stdio_mutex;
MaxAigner 5:c1722555cc45 7 string teststring;
emilmont 1:0f886ffbe0c1 8
emilmont 1:0f886ffbe0c1 9 void notify(const char* name, int state) {
MaxAigner 5:c1722555cc45 10 int counter;
emilmont 1:0f886ffbe0c1 11 stdio_mutex.lock();
MaxAigner 5:c1722555cc45 12 counter ++;
MaxAigner 5:c1722555cc45 13 teststring = "hallo welt %a" , counter;
emilmont 1:0f886ffbe0c1 14 stdio_mutex.unlock();
emilmont 1:0f886ffbe0c1 15 }
emilmont 1:0f886ffbe0c1 16
emilmont 1:0f886ffbe0c1 17 void test_thread(void const *args) {
emilmont 1:0f886ffbe0c1 18 while (true) {
emilmont 1:0f886ffbe0c1 19 notify((const char*)args, 0); Thread::wait(1000);
emilmont 1:0f886ffbe0c1 20 notify((const char*)args, 1); Thread::wait(1000);
emilmont 1:0f886ffbe0c1 21 }
emilmont 1:0f886ffbe0c1 22 }
emilmont 1:0f886ffbe0c1 23
emilmont 1:0f886ffbe0c1 24 int main() {
emilmont 1:0f886ffbe0c1 25 Thread t2(test_thread, (void *)"Th 2");
MaxAigner 5:c1722555cc45 26
MaxAigner 5:c1722555cc45 27 while (1)
MaxAigner 5:c1722555cc45 28 {
MaxAigner 5:c1722555cc45 29 stdio_mutex.lock();
MaxAigner 5:c1722555cc45 30 printf( "%s" , teststring);
MaxAigner 5:c1722555cc45 31 stdio_mutex.unlock();
MaxAigner 5:c1722555cc45 32 wait_ms(100);
MaxAigner 5:c1722555cc45 33 }
emilmont 1:0f886ffbe0c1 34
emilmont 1:0f886ffbe0c1 35 }