Threads and TCP/IP
Thomas Charron
twaffle at gmail.com
Mon Nov 21 18:20:01 EST 2005
On 11/21/05, Cole Tuininga <colet at code-energy.com> wrote:
>
> Let's say you have a tcp/ip socket in a given multi-threaded program.
> And let's further say that you have one thread specifically for reading,
> and one thread specifically for writing.
> Is it legitimate to have the two threads doing their respective
> operation on the socket simultaneously? In other words, can you
> simultaneously read and write a tcp/ip socket? Or would the threads
> need to do some locking themselves to make sure this doesn't happen?
Yes, so long as the underlying libraries used are thread safe. In most
cases, the calls end up blocking in a FIFO method. So if you have 2 threads,
one reading, one writing, the order that they take place is the order then
got called. Yes, one could say 'What about at the same time', but there
really isn't such a thing.. ;-)
> This isn't a "I'm trying to..." question, I have no practical example or
> reason for asking. Just good old fashioned geek curiostiy. 8)
Just please, for the love of god, dont have multiple threads trying to
WRITE to the socket at the same time. Oh, it'll work.. But the data won't
look pretty unless the data packets are REALLY small.
Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.gnhlug.org/mailman/private/gnhlug-discuss/attachments/20051121/dd81a498/attachment.html
More information about the gnhlug-discuss
mailing list