ESP32 multi-tasking?

Hi @alvarolb

I have some questions about how to use thing.lock(); and thing.unlock();

1) If there is a shared resource in the thing object ( eg: ‘Serial.println’ in thing[“print_alert”], executed in CORE_0 ) and a function (CORE_1), we must also use thing.lock(); and thing.unlock(); in the thing[“print_alert”] object? See the example below:

int threshold = 0;

void setup() {
   Serial.begin(115200);

   thing["print_alert"] = [](){
        thing.lock();
        threshold++;
        Serial.println(threshold);
        thing.unlock();
      };

   thing.start();
}

void loop() {
   delay(1000);
   thing.lock();
   threshold++;
   Serial.printf("Threshold value: %d\n", threshold);
   thing.unlock();
}

2) If there are multiple shared resources, the recommended thing would be to create a mutex semaphore for each resource, correct? But with thing.lock(); and thing.unlock(); we just use one mutex semaphary for all resources, correct? See the fictional example below:

int threshold = 0;

void setup() {
   Serial.begin(115200);

   thing["print_alert"] = [](){

  thing.lock("mutex_1");
  threshold++;
  thing.unlock("mutex_1");

  thing.lock("mutex_2");
  Serial.println(threshold);
  thing.unlock("mutex_2");
      };

   thing.start();
}

void loop() {
   delay(1000);
   thing.lock("mutex_1");
   threshold++;
   thing.unlock("mutex_1");

   thing.lock("mutex_2");
   Serial.printf("Threshold value: %d\n", threshold);
   thing.unlock("mutex_2");
}

3) The thing object does not execute xSemaphoreTake(semaphore_, portMAX_DELAY);, nor xSemaphoreGive(semaphore_); when it is running in CORE_0, correct? So, what happens if thing (CORE_0) executes the same feature that is in a function in CORE_1 (which uses thing.lock(); and thing.unlock(); ) ? Does the thing object (which has no internal mutex) take the function’s resource? Or is it blocked, waiting for the function (CORE_1) to release the resource?

4) If thing(CORE_0) is waiting for the WiFi or GSM connection, can it block/lock a function (CORE_1) that shares the same resource, example: Serial.print?