Malloc and free threadsafe?

raldone01
Posts: 4
Joined: Thu Apr 18, 2019 9:37 pm

Malloc and free threadsafe?

Postby raldone01 » Thu Jul 11, 2019 9:48 am

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.

ESP_Angus
Posts: 1817
Joined: Sun May 08, 2016 4:11 am

Re: Malloc and free threadsafe?

Postby ESP_Angus » 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

Ritesh
Posts: 1085
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Malloc and free threadsafe?

Postby Ritesh » Sat Jul 13, 2019 10:10 am

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?
Regards,
Ritesh Prajapati

Who is online

Users browsing this forum: Baidu [Spider], roland and 13 guests