Is socket.send thread safe?
bauss
jj_1337 at live.dk
Mon Mar 26 17:55:10 UTC 2018
On Monday, 26 March 2018 at 16:14:31 UTC, Jonathan wrote:
> Can I send data over an std.socket on multiple threads without
> manual mutexing?
>
> If not, can I send data on a separate thread than receive?
>
> The docs for std.socket say nothing of it (which I guess means
> I should assume it is not thread safe but...).
>
> Thanks!
Define thread safe.
It's safe in the way that the buffers each call to send will have
will be what you expect.
Ex.
thread1 sends [1,2,3] and thread2 sends [4,5,6]
then you're guaranteed that what you receive would be [1,2,3] and
[4,5,6].
What it isn't safe from would be race conditions.
So you don't know if you get it like [1,2,3,4,5,6] or
[4,5,6,1,2,3].
So if the order of the buffer matters then you should use a
mutex, but if the order doesn't matter then you don't need to.
More information about the Digitalmars-d-learn
mailing list