Reputation: 699
Alright so basically I have 3 threads.
Each one of them use a function which inside uses the send() on a specific socket (let's call it S). Here's a small design:
How would I synchronize the S socket in such a way so that send() will be called one after another in a queue instead of the threads accessing the socket all at the same time?
Upvotes: 2
Views: 428
Reputation: 84239
First, why not have an actual queue of data to be sent, and a dedicated IO thread popping items off of it and writing to the socket?
Then, if you are using regular blocking socket semantics, you can just write to the same socket from all three threads concurrently - the kernel will provide required locking at the system call level.
Upvotes: 4