updated for mbed os 5.4
Fork of Task641 by
Revision 5:31707531f715, committed 2016-03-09
- Comitter:
- noutram
- Date:
- Wed Mar 09 17:55:53 2016 +0000
- Parent:
- 4:dae8898e55fe
- Child:
- 6:2e463846b575
- Commit message:
- Solution to 6.1.7 - by changing the sequence in which the locks are taken.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Mar 09 17:18:55 2016 +0000
+++ b/main.cpp Wed Mar 09 17:55:53 2016 +0000
@@ -33,6 +33,7 @@
{
pc.printf("Entering thread 1\n");
while (true) {
+ yellowLED = 1;
//Start critical section
lock1.lock();
@@ -40,19 +41,18 @@
sw1Count++;
printf("\nCount1 = %lu", sw1Count);
- //Thread::wait(1); //1ms
-
- if (SW1 == 1) {
- yellowLED = 1;
- lock2.lock();
- sw2Count--;
- lock2.unlock();
- yellowLED = 0;
- }
+ Thread::wait(1); //1ms
//End critical section
lock1.unlock();
+
+ if (SW1 == 1) {
+ lock2.lock();
+ sw2Count--;
+ lock2.unlock();
+ }
+ yellowLED = 0;
Thread::wait(DELAY);
}
}
@@ -61,6 +61,7 @@
{
pc.printf("Entering thread 2\n");
while (true) {
+ redLED = 1;
//Start critical section
lock2.lock();
@@ -68,19 +69,20 @@
sw2Count++;
printf("\nCount2 = %lu", sw2Count);
- //Thread::wait(1); //1ms
+ Thread::wait(1); //1ms
- if (SW2 == 1) {
- redLED = 1;
+ //End critical section
+ lock2.unlock();
+
+ if (SW2 == 1) {
lock1.lock();
sw1Count--;
lock1.unlock();
- redLED = 0;
}
- //End critical section
- lock2.unlock();
+
+ redLED = 0;
+ Thread::wait(DELAY);
- Thread::wait(DELAY);
}
}
Nicholas Outram