user1255454
user1255454

Reputation: 699

Synchronizing socket send()

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:

http://i.imgur.com/5N744.png

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

Answers (1)

Nikolai Fetissov
Nikolai Fetissov

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

Related Questions