Home > Archive > Unix Programming > September 2006 > Reading and writing to socket from different threads
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Reading and writing to socket from different threads
|
|
| d_m_huffman@hotmail.com 2006-09-15, 7:00 pm |
| Hello,
I have a socket programming question. We have a socket which we
would like to share between threads. One thread will always be the
writer (it will never read from the socket), and one thread will always
be the reader (it will never write to the socket). There will always
be only one writer and only one reader. Do we need to control access
to the socket, or is it okay for the two threads to access it
simultaneously?
Thank you!
Mark
| |
| James Carlson 2006-09-15, 7:00 pm |
| d_m_huffman@hotmail.com writes:
> I have a socket programming question. We have a socket which we
> would like to share between threads. One thread will always be the
> writer (it will never read from the socket), and one thread will always
> be the reader (it will never write to the socket). There will always
> be only one writer and only one reader. Do we need to control access
> to the socket, or is it okay for the two threads to access it
> simultaneously?
You didn't mention what OS you're using. You should consult the
documentation for your operating system and see what it says about the
thread-safety of these interfaces.
In general, though, yes, that should work just fine.
--
James Carlson, KISS Network <james.d.carlson@sun.com>
Sun Microsystems / 1 Network Drive 71.232W Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677
| |
| David Schwartz 2006-09-15, 7:00 pm |
|
d_m_huffman@hotmail.com wrote:
> I have a socket programming question. We have a socket which we
> would like to share between threads. One thread will always be the
> writer (it will never read from the socket), and one thread will always
> be the reader (it will never write to the socket). There will always
> be only one writer and only one reader. Do we need to control access
> to the socket, or is it okay for the two threads to access it
> simultaneously?
Just make sure neither thread could possibly be operating on the socket
before you allow any thread to 'close' it. Otherwise, you should have
no problems.
DS
| |
| d_m_huffman@hotmail.com 2006-09-15, 9:59 pm |
|
James Carlson wrote:
> d_m_huffman@hotmail.com writes:
>
> You didn't mention what OS you're using.
James,
Thank you for your input. We are using VxWorks.
Thanks,
Mark
> --
> James Carlson, KISS Network <james.d.carlson@sun.com>
> Sun Microsystems / 1 Network Drive 71.232W Vox +1 781 442 2084
> MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677
| |
| d_m_huffman@hotmail.com 2006-09-15, 9:59 pm |
|
David Schwartz wrote:
> d_m_huffman@hotmail.com wrote:
>
>
> Just make sure neither thread could possibly be operating on the socket
> before you allow any thread to 'close' it. Otherwise, you should have
> no problems.
>
> DS
Dave,
Great. Thank you very much for your response.
--Mark
|
|
|
|
|