From 8d7f1ccd793dd666d018d87f7237025da67db9d8 Mon Sep 17 00:00:00 2001 From: Chris Veigl Date: Fri, 13 Dec 2024 03:41:55 +0100 Subject: [PATCH 1/2] added taskYield() added taskYield() after giving the Semaphore to allow task2 to run, shortened taskname string parameter --- .../esp32-freertos-06-demo-mutex.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/06-mutex/esp32-freertos-06-demo-mutex/esp32-freertos-06-demo-mutex.ino b/06-mutex/esp32-freertos-06-demo-mutex/esp32-freertos-06-demo-mutex.ino index 3b67667..1c9abcc 100644 --- a/06-mutex/esp32-freertos-06-demo-mutex/esp32-freertos-06-demo-mutex.ino +++ b/06-mutex/esp32-freertos-06-demo-mutex/esp32-freertos-06-demo-mutex.ino @@ -49,6 +49,7 @@ void incTask(void *parameters) { // Give mutex after critical section xSemaphoreGive(mutex); + taskYIELD(); // give the other task a chance to run } else { // Do something else @@ -77,7 +78,7 @@ void setup() { // Start task 1 xTaskCreatePinnedToCore(incTask, - "Increment Task 1", + "IncTask 1", // Note: max length of taskname parameter is 16 (including '\0') 1024, NULL, 1, @@ -86,7 +87,7 @@ void setup() { // Start task 2 xTaskCreatePinnedToCore(incTask, - "Increment Task 2", + "IncTask 2", // Note: max length of taskname parameter is 16 (including '\0') 1024, NULL, 1, From 995963c9aa76801bf0c129075a39ee7a3619b873 Mon Sep 17 00:00:00 2001 From: Chris Veigl Date: Fri, 13 Dec 2024 03:47:26 +0100 Subject: [PATCH 2/2] added print taskname print taskname to Serial, to verify that both tasks are active --- .../esp32-freertos-06-demo-mutex.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/06-mutex/esp32-freertos-06-demo-mutex/esp32-freertos-06-demo-mutex.ino b/06-mutex/esp32-freertos-06-demo-mutex/esp32-freertos-06-demo-mutex.ino index 1c9abcc..b1874bd 100644 --- a/06-mutex/esp32-freertos-06-demo-mutex/esp32-freertos-06-demo-mutex.ino +++ b/06-mutex/esp32-freertos-06-demo-mutex/esp32-freertos-06-demo-mutex.ino @@ -45,6 +45,7 @@ void incTask(void *parameters) { // Print out new shared variable // This is different than in the video--print shared_var inside the // critical section to avoid having it be changed by the other task. + Serial.print(pcTaskGetName(NULL)); Serial.print(" : "); Serial.println(shared_var); // Give mutex after critical section