Page 1 of 1

Malloc and free threadsafe?

Posted: Thu Jul 11, 2019 9:48 am
by raldone01
I want to access I2C functionality from multiple tasks. My current plan is to have one task communicate with the I2C driver (the handler task) and pass the i2c_cmd_handle_t s which are created by different tasks to the handler task. Once the handler is done it should free the i2c_cmd_handle_t s.
So my question is:
Can one task malloc something and another task free that allocated memory?
Do I have to protect malloc and free from being accessed by multiple tasks at the same time.

I read through https://docs.espressif.com/projects/esp ... alloc.html but it didn't answer my questions.

Re: Malloc and free threadsafe?

Posted: Fri Jul 12, 2019 5:37 am
by ESP_Angus
This question was also asked on GitHub, and has been discussed there:
https://github.com/espressif/esp-idf/issues/3768

Re: Malloc and free threadsafe?

Posted: Sat Jul 13, 2019 10:10 am
by Ritesh
ESP_Angus wrote:
Fri Jul 12, 2019 5:37 am
This question was also asked on GitHub, and has been discussed there:
https://github.com/espressif/esp-idf/issues/3768
Hello,

Here discussion about malloc and free threadsafe w.r.t. ISR and question is about to tasks.

So, I have also heard that malloc and free are not threadsafe for normal execution except ISR.

Would you please clarify from your end as well?