title: Can two threads simultaneously `send` and `recv` on the same socket?
body: <p>I need to repeatedly send and receive UDP datagrams to/from a socket. My idea was to spawn two threads, one responsible for sending and the other for receiving. The whole idea makes sense only if it is possible to one thread to wait on a blocking <code>recv()</code> and the other executing <code>send()</code> on the same socket at the same time.</p>
  
  <p>I did some Googling and found this SO question: <a href="https://stackoverflow.com/questions/1981372/are-parallel-calls-to-send-recv-on-the-same-socket-valid">Are parallel calls to send/recv on the same socket valid?</a> The accepted answer mentions that <code>send()</code> and <code>recv()</code> are thread-safe (whew…), but then proceeds with an alarming remark:</p>
  
  <blockquote>
    <p>This doesn't necessarily mean that they'll be executed in parallel</p>
  </blockquote>
  
  <p>Oops. Does this mean that if I implement my multithreaded idea, will I end up with the sending thread waiting for the receiving thread’s <code>recv()</code> to return before it actually starts sending its data? Bad.</p>
  
  <p>It is ambiguous whether this accepted answer refers to two parallel <code>send()</code>’s only, or if the concern is real also for an attempt to parallely execute one <code>send()</code> and one <code>recv()</code>. Therefore:</p>
  
  <p>Will a call to <code>send()</code> and a call to <code>recv()</code> on the same socket by two threads be executed parallely, or will one of these calls block until the other returns?</p>