I'm writing a messaging client, for a single socket. I have 2 threads: one that merely responds to server requests and one that starts sending messages at a specific time. Now, I found that on linux, this might result in a data order problem: when the 2 threads call the 'send()' function at the same time, the data might arrive split and mangled. What I mean is that in this case, the server might first receive the first 50% of packet 1, then the whole packet 2 and then the remainder of packet 1.
Now, my application is extremely performance/latency sensitive, how do I solve this with minimum performance impact ?
If both applications are on the same processor, then you may want to look into IPC shared memory to transfer data. It'll be far quicker with lower latency.