Reputation: 675
Hi I am new to C++/C and I have a question: Is it thread safe to call socket send to different sockets from different threads? I can find answer on stackoverflow that message may be jumbled upon receive when calling send() to SAME socket from different threads. What about calling send() to DIFFERENT sockets from different threads? Is it thread safe? Thank you.
#include <sys/types.h>
#include <sys/socket.h>
send(1, buf1, buf1.size(), 0); //call from thread1
send(2, buf2, buf2.size(), 0); //call from thread2
Upvotes: 0
Views: 1020
Reputation: 597941
It is perfectly safe for separate threads to call send()
to different sockets at the same time.
Like you said, the only time you need to worry is when separate threads are trying to send()
to the same socket at the same time, that needs to be coordinated accordingly.
Upvotes: 1