0

Are Unix multicast sockets thread safe?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 2
    Are Unix sockets thread safe? Multicast sockets will be as thread safe as any other form of socket. – Jonathan Leffler Jun 05 '12 at 11:06
  • `unix sockets` can be http://en.wikipedia.org/wiki/Unix_domain_socket, but these don't have multicast or sockets as used in 'unix', but these can be all kind of posix compatible socket implementations. I would not let several threads send on any socket without locking and I would let only one thread read from any socket. – stefaanv Jun 05 '12 at 11:14

1 Answers1

3

Depends on what you mean by thread-safe. It appears that making to calls to send() at the same time from separate threads will not crash your program, and all the data will be send across the network.

The problem is that if your message stretches across more than one packet. The packets may interleave and it will be up to the remote machine to sort out the two interleaved messages.

See: Be careful with the sendmsg() family of functions which I got from Are parallel calls to send/recv on the same socket valid?.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117