title: Are parallel calls to send/recv on the same socket valid as per POSIX standard?
body: <p>I am trying to understand the usage of socket APIs (<code>recv</code>, <code>send</code>, <code>select</code>, <code>close</code>, etc) on parallel threads. That means using one socket file descriptor on two parallel threads. I have gone through <a href="https://stackoverflow.com/questions/1981372/are-parallel-calls-to-send-recv-on-the-same-socket-valid">this</a> question. But still I am not able to find any standard doc which explains the usage of socket APIs in multiple thread. Even <a href="http://pubs.opengroup.org/onlinepubs/009695399/functions/recv.html" rel="noreferrer">opengroup</a> man page is not telling anything about this.</p>
  
  <p>I also want to know whether below listed parallel thread usage scenarios are valid in POSIX socket APIs</p>
  
  <p>1) Calling <code>recv</code> and <code>send</code> in two parallel threads</p>
  
  <pre><code>int main_thread() {
      fd = do_connect(); //TCP or UDP
      spawn_thread(recv_thread, fd);
      spwan_thread(send_thread, fd);
      ...
  }
  
  int recv_thread(fd) {
      while(1) {
          recv(fd, ..)
          ...
      }
  }
  
  int send_thread(fd) {
      while(1) {
          send(fd, ..)
          ...
      }
  }
  </code></pre>
  
  <p>2) Calling <code>recv</code> and <code>send</code> with <code>select</code> in two parallel threads</p>
  
  <pre><code>int recv_thread(fd) {
      while(1) {
          select(fd in readfd)
          recv(fd, ..)
          ...
      }
  }
  
  int send_thread(fd) {
      while(1) {
          select(fd in write)
          send(fd, ..)
          ...
      }
  }
  </code></pre>
  
  <p>3) Calling <code>recv</code> and <code>send</code> with <code>setsockopt</code>, <code>ioctl</code>, <code>fcntl</code> in two paralle threads</p>
  
  <pre><code>int recv_thread(fd) {
      int flag = 1
      while(1) {
          ioctl(fd, FIONBIO, &amp;flag); //enable non block
          recv(fd, ..)
          flag = 0;
          ioctl(fd, FIONBIO, &amp;flag); //disable non block
          ...
      }
  }
  
  int send_thread(fd) {
      while(1) {
          select(fd in write)
          send(fd, ..)
          ...
      }
  }
  </code></pre>