Re: Threading safety question

Giganews Newsgroups
Subject: Re: Threading safety question
Posted by:  Remy Lebeau (TeamB) (no.spam@no.spam.com)
Date: Wed, 14 Sep 2005

"Simon A." <saberu…@tecnar-automation.com> wrote in message
news:E4EC75F32DDAE240saberu…@tecnar-automation.com...

> my principal question if this is safe to use directly the writebuffer
method
> of the client from another thread (with readbuffer method called from the
> thread that owned the client at the same time).

Yes, it is safe to write from one thread while simultaneously reading in
another.  A socket maintains multiple buffers internally for exactly that
purpose.  As long as the reading thread does not also write to the socket,
then it is safe.  However, if the reading thread does also write, then you
need to provide your own protected access to the socket so that only one
thread can write at any given time.  If both threads are allowed to write to
the socket at the same time, then the two data blocks will overlap each
other and corrupt your communication.

Gambit

Replies

None

In response to

Threading safety question posted by Simon A. on Wed, 14 Sep 2005