[Mono-list] threads and Async Socket methods

P Oscar Boykin boykin@pobox.com
Tue, 27 Apr 2004 17:33:04 -0700

Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hello All,

I have some code that does asynchronous Socket.BeginSend and
Socket.BeginReceive calls.

My question is the following:

1) The documentation (in monodoc) says that no instance members of
Socket are guaranteed to be thread safe.

2) Given the above, is it safe to have a BeginSend call active while a
BeginReceive call is also active?  Given that the "under the hood" it
appears that these methods are implemented with threads.

So, to make it clear, if I have code like:


[ other stuff here ]


is this safe?  To me, it would seem like it would not be safe if none of
the members are guaranteed to be thread safe, but on the other hand, I
have a C# networking book that has examples such as this.

The reason I ask is that I have some code that (on mono 0.31) appears
that *SOMETIMES* the BeginSend never calls the callback function to
indicate that it finished (and the other side never gets the data).
This is happening while a BeginReceive() is active.

When I see bugs that happen only sometimes, it usually makes me worry
about thread safety.  It would be nice if the Begin* methods were
designed such that there could be more than one of them active at a time
(particularly, it would be nice to have a send going on while a receive
was also active).

Am I expecting too much here?

boykin@pobox.com    http://pobox.com/~boykin    jabber: johnynek@jabber.org
fingerprint=3DD250 4AD9 4544 B7D2 A17C  911D D608 D387 6718 D75F
Hague Convention is Bad News: http://www.gnu.org/philosophy/hague.html

Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

Version: GnuPG v1.2.4 (GNU/Linux)