Oliver Ainhirn
/
82_Thread_Semaphore
Semaphore_Display
Diff: main.cpp
- Revision:
- 2:9a1b2edd0b0d
- Parent:
- 1:98ffcc251be8
--- a/main.cpp Thu Mar 21 18:13:40 2019 +0000 +++ b/main.cpp Thu Mar 21 18:20:01 2019 +0000 @@ -60,6 +60,7 @@ Mutex LCDMutex; // hier wird der Mutex instanziiert +Semaphore one_slot(3);// die Anzahl der gleichzeitig erlaubten Threads bei 1 darf immer nur einer hier bei 3 haben wir wieder das Problem das alles gleichzeitig losgehen kann //void Led1_Blink(void *pvParameters) void Led1_Blink() // red long @@ -73,7 +74,8 @@ wait_ms(xDelay); } // kritischer abschnitt!!! dieser soll mit Mutex behandelt werden - LCDMutex.lock();// Mutex beginnt + //LCDMutex.lock();// Mutex beginnt + one_slot.wait(); { lcd.cls(); lcd.locate(0,3); @@ -86,7 +88,8 @@ Delay_Nonsense(&BlueDelay, &TargetCount); wait_ms(xDelay); } - LCDMutex.unlock(); // Mutex endet + //LCDMutex.unlock(); // Mutex endet + one_slot.release(); } } @@ -100,7 +103,8 @@ for(int i = 0; i < 10; i++) { // randomnes wait_ms(xDelay); } - LCDMutex.lock();// Mutex beginnt + //LCDMutex.lock();// Mutex beginnt + one_slot.wait(); { lcd.cls(); lcd.locate(0,3); @@ -113,7 +117,8 @@ Delay_Nonsense(&BlueDelay, &TargetCount); wait_ms(xDelay); } - LCDMutex.unlock(); // Mutex endet + //LCDMutex.unlock(); // Mutex endet + one_slot.release(); } } @@ -127,7 +132,8 @@ for(int i = 0; i < 10; i++) { // randomnes wait_ms(xDelay); } - LCDMutex.lock();// Mutex beginnt + //LCDMutex.lock();// Mutex beginnt + one_slot.wait(); { lcd.cls(); lcd.locate(0,3); @@ -141,7 +147,8 @@ Delay_Nonsense(&BlueDelay, &TargetCount); wait_ms(xDelay); } - LCDMutex.unlock(); // Mutex endet + //LCDMutex.unlock(); // Mutex endet + one_slot.release(); } }