Concurrent socket usage from multiple tasks

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Concurrent socket usage from multiple tasks

Postby kolban » Tue Feb 21, 2017 9:49 pm

We are now starting to get into what I would consider to be more advanced concepts. Here is one I put forward to us as a community ... are sockets thread safe with respect to reading and writing?

Imagine I have a FreeRTOS task that invokes a socket recv() API call and is blocked waiting for incoming TCP data. Now imagine a second task that is running in parallel to the first. Is this second task allowed to make a TCP send() API call on the SAME socket while the other task is blocked on a recv()?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

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

Re: Concurrent socket usage from multiple tasks

Postby ESP_Angus » Wed Feb 22, 2017 1:39 am

Yes, this should work. The receiving task will remain blocked until the other end of the TCP connection has sent data.

Who is online

Users browsing this forum: No registered users and 317 guests