Problems with Pthread.h. ESP32-DevKitC-V4

javioreja
Posts: 1
Joined: Fri Mar 03, 2023 1:10 pm

Problems with Pthread.h. ESP32-DevKitC-V4

Postby javioreja » Fri Mar 03, 2023 1:18 pm

I'm trying to program an ESP32 DevKitC-V4 board with the Pthread.h library in Arduino IDE 1.8.19 and I got an error. Trying to narrow down the error, I loaded an example code with the same library and still got the same error:

Code: Select all

#include <pthread.h>
 
void *printThreadId(void *threadid) {
   Serial.println((int)threadid);
}
 
void setup() {
 
   Serial.begin(115200);
 
   pthread_t threads[4];
   int returnValue;
 
   for( int i = 0; i< 4; i++ ) {
 
      returnValue = pthread_create(&threads[i], NULL, printThreadId, (void *)i);
 
      if (returnValue) {
         Serial.println("An error has occurred");
      }
   }
 
}
 
void loop() {}
When I look at the serial monitor y see this error:

Guru Meditation Error: Core 0 panic'ed (IllegalInstruction). Do you have any idea what the problem might be?

ESP_Sprite
Posts: 9727
Joined: Thu Nov 26, 2015 4:08 am

Re: Problems with Pthread.h. ESP32-DevKitC-V4

Postby ESP_Sprite » Sat Mar 04, 2023 12:04 am

Not sure if pthreads work the same as FreeRTOS tasks, but if they do, it's not valid to have a thread function return. If this is indeed the issue, you should have the thread delete itself first via pthread_exit.

Who is online

Users browsing this forum: Basalt and 41 guests