views:

166

answers:

1

Hello,

i am running eCos with the FreeBSD TCP/IP-stack. Is it safe to have two threads running one to read from a socket and one to write to the same socket?

Well i guess since its the FreeBSD stack the operating system does not matter.

Best regards,

Friedrich

A: 

AFAIK, sockets are full duplex, meaning we can read from and write to the same socket at the same time. However, you have to make sure that there's only 1 reader and 1 writer at a time. Please correct me if I was wrong.

shinkou
You are not wrong. One thread can be reading while another thread is writing at the same time. If multiple threads read, or multiple threads write, you have to manually serialize access to that side of the socket to prevent overlaps.
Remy Lebeau - TeamB