Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is AF_UNIX socket send thread safe? [duplicate]

Looked around, but could not find any link justifying the answer for AF_UNIX sockets.

My implementation is on a linux system, I have an AF_UNIX SOCK_STREAM socket,

  • one receiver thread on this socket
  • few worker threads which can call 'send()' on this socket.

My question is - are AF_UNIX socket 'send()' thread safe? If I have threads parallely/concurrently calling send on the AF_UNIX socket fd, will kernel take care of the synchronization?

I went through multiple links, but all are related to TCP/UDP (AF_INET) sockets, so if anyone could suggest a link that justifies the answer, or could provide some insight into the kernel code, it would be of great help.

like image 618
greenhorn Avatar asked Mar 14 '23 03:03

greenhorn


1 Answers

POSIX specifies that all functions it defines must be thread-safe, except those on a list of specific exceptions. The send(2) function is defined by POSIX and is not included on the list of exceptions. Inasmuch as the Linux implementation of send(2) purports to conform to POSIX specifications, you can rely on it to be thread-safe.

like image 161
John Bollinger Avatar answered Mar 23 '23 11:03

John Bollinger