Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Task617-mbedos by
Revision 1:4fb27aea76b2, committed 2016-03-08
- Comitter:
- noutram
- Date:
- Tue Mar 08 12:26:28 2016 +0000
- Parent:
- 0:f916cefba2f4
- Child:
- 2:70084af839d3
- Commit message:
- Solution for 6.1.5
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Mar 08 11:43:39 2016 +0000
+++ b/main.cpp Tue Mar 08 12:26:28 2016 +0000
@@ -20,9 +20,8 @@
DigitalIn SW1(D4);
DigitalIn SW2(D3);
-//Thread object references
-Thread* t1;
-Thread* t2;
+//MUTEX Lock
+Mutex *countLock;
//Thread ID for the Main function (CMSIS API)
osThreadId tidMain;
@@ -36,6 +35,10 @@
redLED = 1;
for (unsigned int n=0; n<10000; n++) {
+ //Take lock
+ countLock->lock();
+
+ //Critical section(s)
count++;
count++;
count++;
@@ -46,6 +49,9 @@
count++;
count++;
count++;
+
+ //Release lock
+ countLock->unlock();
}
redLED = 0;
@@ -57,6 +63,10 @@
yellowLED = 1;
for (unsigned int n=0; n<10000; n++) {
+ //Take lock
+ countLock->lock();
+
+ //Critical section(s)
count--;
count--;
count--;
@@ -66,7 +76,10 @@
count--;
count--;
count--;
- count--;
+ count--;
+
+ //Release lock
+ countLock->unlock();
}
osSignalSet(tidMain, YELLOW_DONE); //Signal main thread we are done
@@ -83,6 +96,9 @@
//Main thread ID
tidMain = Thread::gettid();
+ //Create lock
+ countLock = new Mutex();
+
//Press the switch to run concurrently
if (onBoardSwitch == 1) {
printf("Running sequntially\n");
@@ -102,5 +118,9 @@
if (count == 0) {
greenLED = 0;
}
+
+ //Tidy
+ delete countLock;
+
while(true);
}
