SEU_G10
/
rtos_4
rtos4
Fork of rtos_basic by
main.cpp@7:68fb4465a2c3, 2015-11-13 (annotated)
- Committer:
- xiscosc
- Date:
- Fri Nov 13 14:43:17 2015 +0000
- Revision:
- 7:68fb4465a2c3
- Parent:
- 3:c92e21f305d8
rtos4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:491820ee784d | 1 | #include "mbed.h" |
emilmont | 1:491820ee784d | 2 | #include "rtos.h" |
xiscosc | 7:68fb4465a2c3 | 3 | |
xiscosc | 7:68fb4465a2c3 | 4 | Mutex mux; |
xiscosc | 7:68fb4465a2c3 | 5 | int a; |
xiscosc | 7:68fb4465a2c3 | 6 | |
xiscosc | 7:68fb4465a2c3 | 7 | |
xiscosc | 7:68fb4465a2c3 | 8 | void thread1(void const *args) { |
xiscosc | 7:68fb4465a2c3 | 9 | |
emilmont | 1:491820ee784d | 10 | while (true) { |
xiscosc | 7:68fb4465a2c3 | 11 | mux.lock(); |
xiscosc | 7:68fb4465a2c3 | 12 | a++; |
xiscosc | 7:68fb4465a2c3 | 13 | printf("LOW %d \r\n",a); |
xiscosc | 7:68fb4465a2c3 | 14 | mux.unlock(); |
emilmont | 1:491820ee784d | 15 | } |
emilmont | 1:491820ee784d | 16 | } |
xiscosc | 7:68fb4465a2c3 | 17 | |
xiscosc | 7:68fb4465a2c3 | 18 | void thread2(void const *args) { |
xiscosc | 7:68fb4465a2c3 | 19 | |
emilmont | 1:491820ee784d | 20 | while (true) { |
xiscosc | 7:68fb4465a2c3 | 21 | mux.lock(); |
xiscosc | 7:68fb4465a2c3 | 22 | a++; |
xiscosc | 7:68fb4465a2c3 | 23 | printf("HIGH %d \r\n",a); |
xiscosc | 7:68fb4465a2c3 | 24 | mux.unlock(); |
xiscosc | 7:68fb4465a2c3 | 25 | } |
emilmont | 1:491820ee784d | 26 | } |
xiscosc | 7:68fb4465a2c3 | 27 | |
xiscosc | 7:68fb4465a2c3 | 28 | int main() { |
xiscosc | 7:68fb4465a2c3 | 29 | a = 0; |
xiscosc | 7:68fb4465a2c3 | 30 | Thread my_thread1(thread1, NULL, osPriorityLow); |
xiscosc | 7:68fb4465a2c3 | 31 | Thread::wait(10); |
xiscosc | 7:68fb4465a2c3 | 32 | Thread my_thread2(thread2, NULL, osPriorityHigh); |
xiscosc | 7:68fb4465a2c3 | 33 | |
xiscosc | 7:68fb4465a2c3 | 34 | while (true) { |
xiscosc | 7:68fb4465a2c3 | 35 | printf("MEDIUM \r\n"); |
xiscosc | 7:68fb4465a2c3 | 36 | } |
xiscosc | 7:68fb4465a2c3 | 37 | } |