SuperHouse / esp-open-rtos

Open source FreeRTOS-based ESP8266 software framework
BSD 3-Clause "New" or "Revised" License
1.53k stars 491 forks source link

Data Races #560

Open Zaltora opened 6 years ago

Zaltora commented 6 years ago

Just a question. I got multiple global variable ( Read-only acces through a extern const pointer outside of the file) in my app. It is possible to get data races problem with esp8266 (one core) ? If yes, using "Critical rtos API" can help ? bonus: esp32 can get this problem (2 core)?

Zaltora commented 6 years ago

Sometimes i get random reboot on error. The cause of error is related to memory problem and I can not reproduce the error by doing the same things that led me to the error.

I am not out of memory: RTOS heap => +10kBytes I was thinking of free/malloc problem, but after check i see nothing. Anyway when i can't reproduce. the random reboot rarely happens. I suppose a memory alignment problem too but i don't no how check it. I suppose a memory access between task problem so i begin to change my system and use local variable for treatments then write it in a global variable (read-only) with vEnterCritical() API but i don(t no if it is will got effect or it is useless.

flannelhead commented 6 years ago

@Zaltora, critical section is of course an effective way of protecting from concurrent access. However that is also a bit heavy-handed approach. FreeRTOS also has a mutex API (see the FreeRTOS) docs, which you can even use from ISRs.

To your original question: yes, race conditions can be a problem even though we have only one core - after all there are multiple concurrent tasks running.

Zaltora commented 6 years ago

Yeah forget about mutex, i will use them. About theses global variable, this problem can appear if two task want read the memory ?. If no i guess i need protect the writing ? Other situation: