Skip to main content
gamedev.net
🔒 Locked

send() 2 different threads same socket, safe?

Started by ANSI2000 2 replies 900+ views
Original Post
ANSI2000
ANSI2000
How about this for a situtaion... Lets say I call send() from 2 different threads at the same time for the same socket? What would happen?
Baloogan
Baloogan
2 threads one socket... i dunno... y would u need this? (or is it jusdt a therory?)
If you were MEANT to understand it, we wouldn't have called it 'code'
CWizard
CWizard
If you use blocking sockets, it is not very safe, and you should use a critical section around the code, so one thread isn't locked inside a send and the other comes and wants to send something. If you're using async sockets, you can probably get away with it, but that will probably be senseless to do, as you won't have control of the order the data will be sent, and the receiver don't know what it is getting. Either way, use some sort of control mechanism; critcal sections for blocking, or some bool indicating if the socket is "free" when using async.

EDIT: As for what will happen. I do think there is a socket error for "socket busy", which is likely that you'll see if you try it.
---------------------------------------------
"VB is a disease"

[edited by - CWizard on October 26, 2002 9:32:58 PM]
ANSI2000
ANSI2000
Yeah I used a mutex around the 2 sends... It should be ok...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.