[Mono-list] threads and Async Socket methods
Sat, 8 May 2004 02:09:16 +1000
I am not sure if the problem I am experiencing is the same as yours, but I
will explain what appears to be happening to me.
I have a similar program: a TCP server with lots of data being relayed
between the clients. I am using async for accepting, sending and receiving.
When I have about 20 async calls which have not returned for a while, all
subsequent calls lock up until the first calls finish. This happens a lot
when a client stops acknowledging packets, but is not registering as
disconnected. I can see a large send queue value in netstat when this
My questions are:
- Am I completely wrong about what's happening? I will try writing a test
program, but the conditions will be hard to emulate.
- If I am right, is there any way to avoid this? Can I check the send queue
value inside a mono app? I was thinking of keeping a counter of the current
- Can you suggest any diagnostic classes I could try to help me find out
what is really happening? eg finding out what state other threads are in.
Soon I will try Beta 1 to see if this still occurs.
Btw, I have developed this solely using mono and MonoDevelop. I really
appreciate the work you guys do.
[mailto:email@example.com]On Behalf Of P Oscar Boykin
Sent: Wednesday, 28 April 2004 10:33 AM
Subject: [Mono-list] threads and Async Socket methods
I have some code that does asynchronous Socket.BeginSend and
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?
firstname.lastname@example.org http://pobox.com/~boykin jabber: email@example.com
fingerprint=D250 4AD9 4544 B7D2 A17C 911D D608 D387 6718 D75F
Hague Convention is Bad News: http://www.gnu.org/philosophy/hague.html