Crash when accessing attribute from thread
Posted: Fri May 31, 2024 7:31 pm
First of all: Hi to everyone. I have been reading here for while but never joined the community. This site really helped me a lot - thank you!
Now, I have the following problem: When accessing an attribute of the instance of an object from a different thread, the system panics.
This is an example code (that does compile and run):
main
class file
and the header
And I get:
I am using Linux and the current ESP IDF.
Why can't I access the attribute from the spun of thread and what would be the proper way to work around this issue?
Any explainations/suggestions are highly appreciated!
Now, I have the following problem: When accessing an attribute of the instance of an object from a different thread, the system panics.
This is an example code (that does compile and run):
main
Code: Select all
#include "freertos/FreeRTOS.h"
#include "backends/platform/esp32/osystem.h"
extern "C" {
extern void app_main();
}
void app_main(void) {
_Esp32::OSystem_Esp32 * g_system = new _Esp32::OSystem_Esp32();
assert(g_system);
while (1) {
vTaskDelay(1);
}
}
Code: Select all
#include "osystem.h"
#include "freertos/FreeRTOS.h"
namespace _Esp32 {
OSystem_Esp32::OSystem_Esp32() {
xTaskCreatePinnedToCore((TaskFunction_t) &_Esp32::OSystem_Esp32::input_task, "input_task", 1024, NULL, 5, NULL, 0);
}
OSystem_Esp32::~OSystem_Esp32() {}
void OSystem_Esp32::input_task(void* arg) {
_value++; // LoadProhibited
while (1) {
vTaskDelay(1);
}
}
} // namespace _Esp32
Code: Select all
namespace _Esp32 {
class OSystem_Esp32 {
public:
OSystem_Esp32();
virtual ~OSystem_Esp32();
private:
int _value;
private:
void input_task(void* arg);
};
} // namespace _Esp32
Code: Select all
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x4200916e PS : 0x00050030 A0 : 0x00000000 A1 : 0x3fca6f70
0x4200916e: _Esp32::OSystem_Esp32::input_task(void*) at /home/pico/scummesp32/test/components/backends/platform/esp32/osystem.cpp:15
A2 : 0x00000000 A3 : 0x00000000 A4 : 0x00000000 A5 : 0x00000000
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x00000000 A9 : 0x3fc96eb8
A10 : 0x00000000 A11 : 0x00000000 A12 : 0x3fc971b0 A13 : 0x3fca70ec
A14 : 0x3fc971a8 A15 : 0x3fc96eb8 SAR : 0x00000000 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000004 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
Backtrace: 0x4200916b:0x3fca6f70
0x4200916b: _Esp32::OSystem_Esp32::input_task(void*) at /home/pico/scummesp32/test/components/backends/platform/esp32/osystem.cpp:13
Why can't I access the attribute from the spun of thread and what would be the proper way to work around this issue?
Any explainations/suggestions are highly appreciated!