Lin ShengKun
/
rtos_mutex
NYP
Fork of rtos_mutex by
main.cpp@6:1ae0d86d2020, 2017-01-13 (annotated)
- Committer:
- mab5449
- Date:
- Fri Jan 13 19:49:29 2017 +0000
- Revision:
- 6:1ae0d86d2020
- Parent:
- 5:384d6cef11d4
- Child:
- 7:bd0aa7f21f53
Updated to mbed 5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:0f886ffbe0c1 | 1 | #include "mbed.h" |
emilmont | 1:0f886ffbe0c1 | 2 | |
Bartek Szatkowski |
5:384d6cef11d4 | 3 | Mutex stdio_mutex; |
mab5449 | 6:1ae0d86d2020 | 4 | Thread t2; |
mab5449 | 6:1ae0d86d2020 | 5 | Thread t3; |
mab5449 | 6:1ae0d86d2020 | 6 | |
emilmont | 1:0f886ffbe0c1 | 7 | void notify(const char* name, int state) { |
emilmont | 1:0f886ffbe0c1 | 8 | stdio_mutex.lock(); |
emilmont | 1:0f886ffbe0c1 | 9 | printf("%s: %d\n\r", name, state); |
emilmont | 1:0f886ffbe0c1 | 10 | stdio_mutex.unlock(); |
emilmont | 1:0f886ffbe0c1 | 11 | } |
emilmont | 1:0f886ffbe0c1 | 12 | |
emilmont | 1:0f886ffbe0c1 | 13 | void test_thread(void const *args) { |
emilmont | 1:0f886ffbe0c1 | 14 | while (true) { |
mab5449 | 6:1ae0d86d2020 | 15 | notify((const char*)args, 0); wait(1); |
mab5449 | 6:1ae0d86d2020 | 16 | notify((const char*)args, 1); wait(1); |
emilmont | 1:0f886ffbe0c1 | 17 | } |
emilmont | 1:0f886ffbe0c1 | 18 | } |
emilmont | 1:0f886ffbe0c1 | 19 | |
emilmont | 1:0f886ffbe0c1 | 20 | int main() { |
Bartek Szatkowski |
5:384d6cef11d4 | 21 | t2.start(callback(test_thread, (void *)"Th 2")); |
Bartek Szatkowski |
5:384d6cef11d4 | 22 | t3.start(callback(test_thread, (void *)"Th 3")); |
Bartek Szatkowski |
5:384d6cef11d4 | 23 | |
emilmont | 1:0f886ffbe0c1 | 24 | test_thread((void *)"Th 1"); |
emilmont | 1:0f886ffbe0c1 | 25 | } |