title: Is it safe to issue blocking write() calls on the same TCP socket from multiple threads?
body: <p>Let's say I have two threads, T1 and T2.</p>
  
  <p>Thread T1 makes a blocking write() call on a TCP socket S to send a large buffer of bytes B1. The buffer of bytes B1 is so large that (a) the write call blocks and (b) TCP has to use multiple segments to send the buffer.</p>
  
  <p>Thread T2 also makes a blocking write() call on the same TCP socket S to send some other large buffer of bytes B2.</p>
  
  <p>My questions is this:</p>
  
  <p>Does the implementation of TCP on UNIX guarantee that the all bytes of B1 will be sent before all bytes of B2 (or vice versa)?</p>
  
  <p>Or is it possible that TCP interleaves the contents of B1 and B2 (e.g. TCP sends a segment with B1 data, then a segment with B2 data, an then a segment with B1 data again).</p>
  
  <p>PS - I know it is not a good idea to do this. I'm trying to determine whether or not some code which I did not write is correct.</p>