[Mono-dev] Foreing thread lifecycle tracking

Laurent Etiemble laurent.etiemble at monobjc.net
Mon Dec 28 17:55:55 EST 2009


I have posted a proposal for an embedding API to allow foreign thread
tracking (see https://bugzilla.novell.com/show_bug.cgi?id=537764#c26).

The API allows:
- To be notified when a foreign thread is registered with the Mono runtime
- To be notified when a foreign thread is de-registered from the Mono
- To override default Mono behavior by telling that foreign thread are
de-registered externally
- To de-register a foreign thread from the Mono runtime

There are two cases of use:
1) An application hooks the Mono runtime to be notified when foreign thread
are registered/de-registered.
2) An application hooks the Mono runtime to handle the foreign thread
de-registration. When a foreign thread is registered, the application is
notified. The application is then responsible for the de-registration of the
foreign thread.

Some notes:
- The patch has been generated against the 2.6.1 release sources.
- I have put the embedding API in the "mono/utils" folder, because it is
referenced both as a public API and used in the GC.
- I have decorated the API to work only if pthread is present. We can see
later if other platforms have similar needs.
- I only work on the Bohem GC. I don't have taken time to look into the SGen
- I have tested the embedding API on Leopard and Snow Leopard, and it works
at it should for the 2 cases above.

Any comments is welcome.

Regards, Laurent Etiemble.

2009/12/8 Laurent Etiemble <laurent.etiemble at monobjc.net>

> Hello,
> I am starting this thread in order to find a solution to an issue
> encountered with Mono and described in this bug entry
> (https://bugzilla.novell.com/show_bug.cgi?id=537764).
> Short Summary: On Mac OS X, Mono is using POSIX pthread functions to
> hook to TSD (Thread Specific Data) in order to track the lifecycle of
> foreign thread (thread not created by the Mono runtime). Under some
> circumstances, a native-to-managed call can lead to inconsistent state
> in the Garbage Collector.
> As recommended by Geoff, I am starting a discussion about new public
> API to support the notification of thread death/creation in the Mono
> runtime:
> - How thread tracking can be done so Mono does not miss thread death ?
> - What about providing callback functions that override Mono default
> behavior ? They will be set during the Mono bootstrapping.
> Any comments or ideas are welcome.
> Regards, Laurent Etiemble.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20091228/fb33304e/attachment-0001.html 

More information about the Mono-devel-list mailing list