v1
Diff: main.cpp
- Revision:
- 5:31707531f715
- Parent:
- 4:dae8898e55fe
- Child:
- 6:2e463846b575
diff -r dae8898e55fe -r 31707531f715 main.cpp
--- 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);
}
}