
Demonstrates data corruption due to a race condition updated for mbed os 5.4
Revision 2:7e77fec81f7d, committed 2017-03-30
- Comitter:
- noutram
- Date:
- Thu Mar 30 14:12:06 2017 +0000
- Parent:
- 1:8c6ec9de7688
- Commit message:
- Updated for mbed os 5.4
Changed in this revision
--- a/main.cpp Tue Mar 08 12:11:18 2016 +0000 +++ b/main.cpp Thu Mar 30 14:12:06 2017 +0000 @@ -1,13 +1,12 @@ #include "mbed.h" -#include "rtos.h" #define RED_DONE 1 #define YELLOW_DONE 2 //Function declarations -void countUP(void const *args); -void countDOWN(void const *args); +void countUP(); +void countDOWN(); //Digital outputs DigitalOut onBoardLED(LED1); @@ -27,7 +26,7 @@ volatile long long count = 0; //Threads -void countUP(void const *args) +void countUP() { redLED = 1; @@ -48,7 +47,7 @@ osSignalSet(tidMain, RED_DONE); //Signal main thread we are done } -void countDOWN(void const *args) +void countDOWN() { yellowLED = 1; @@ -72,6 +71,8 @@ //Main thread int main() { + Thread t1, t2; + redLED = 0; yellowLED = 0; greenLED = 1; @@ -82,12 +83,12 @@ //Press the switch to run concurrently if (onBoardSwitch == 1) { printf("Running sequntially\n"); - countUP(NULL); - countDOWN(NULL); + countUP(); + countDOWN(); } else { printf("Running concurrently\n"); - Thread t1(countUP); - Thread t2(countDOWN); + t1.start(countUP); + t2.start(countDOWN); //Wait for the ALL_ON signal Thread::signal_wait(RED_DONE,osWaitForever);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Thu Mar 30 14:12:06 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#50b3418e45484ebf442b88cd935a2d5355402d7d
--- a/mbed-rtos.lib Tue Mar 08 12:11:18 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#b4c5542476ba
--- a/mbed.bld Tue Mar 08 12:11:18 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/252557024ec3 \ No newline at end of file