[Mono-list] Re: full duplex sockets and threads

Robert Jordan robertj at gmx.net
Mon May 8 14:10:58 EDT 2006

P. Oscar Boykin wrote:
> Thanks for your reply.  Some more below...
> On 5/8/06, Robert Jordan <robertj at gmx.net> wrote:
>> P. Oscar Boykin wrote:
>> > If anyone else has some good pointers on how to use one socket to send
>> and
>> > receive without polling or using the asynchronous methods I would be
>> happy
>> > to learn of them (polling introduces latency and the asynchronous
>> methods
>> > often lead to deadlocks I guess due to their internal use of
>> threadpools).
>> Supposing the reads & writes are highly interdependent, using
>> asynchronous methods is the fastest way. Having separate threads
>> for reading and writing needs thread synchronization and leads
>> to a context switch.
>> The async methods used by the Socket class are handled differently
>> by the runtime. They are not invoked from the generic TP. The Socket
>> IO is handled by a specialized thread using AIO APIs.
> Is this really true?  I assume you mean posix aio methods?  When I look in
> the mono source I can't find where this is happening.  Am I missing it?  It
> appeared to me that the asynchronous methods were being implemented with
> threading in mono and the standard synchronous socket calls.

See mono/metadata/threadpool.c

The Socket class' async delegates are detected with socket_io_filter ()
and queued with socket_io_add (). The IO worker thread is
async_invoke_thread ().

> Can you provide a reference (file names/line numbers) for the aio code in
> mono?

Sorry, actually I meant Linux AIO. The code is in


More information about the Mono-list mailing list