[Mono-list] Calls to CIL code from native threads
Wed, 28 Jan 2004 12:16:49 +0100
On 01/27/04 Patrick Hartling wrote:
> > Are you really using multiple domains in your app?
> My understand of application domains is still very limited, so I am not
> sure I can answer this question definitively. If threads spawned by
> native code each need their own domain, then yes, I am using multiple
Nope. multiple threads can belong to the same appdomain.
> domains. Is there something different that I could call besides
> mono_domain_create() to get a valid MonoDomain* to hand off to
If you're embedding mono, you get the initial appdomain from
mono_jit_init(). In threads started by mono you can get the current
domain by calling mono_domain_get (). You call also get the domain an
object belongs to by calling mono_dobject_domain (obj).
If you don't know what appdomains are, you don't need to create them, so
don't use mono_domain_create().
> I may not have described my situation in enough detail. I have a C#
> class with a static Main() function that I execute using Mono. That
> class instantiates an object that (conceptually) derives from a native
> C++ object. The C# object is handed off to C++ code where callbacks are
> invoked from a thread spawned by the native code. The end result is
> that a C# object is handled polymorphically by C++ code. The primary
> thread of control in the C# Main() function blocks until the C++ code
> shuts down.
> At this point, I do not have code of my own that calls mono_jit_init().
> In the long term, I probably will, but for now, I am concentrating on
> making C# applications that can activate and utilize the native C++
> libraries I am exposing for use with CLS-compliant languages.
If that case you want to get the domain using mono_object_domain(obj)
where obj is the object you pass to the C++ code. Or use mono_domain_get()
from a thread called from managed code, for example when you first go
from C# to C++ code.
> I think that my analysis regarding a deadlock was wrong. The
> application was hanging, but I do not know where. I modified things so
> that mono_thread_attach() is called precisely once pre thread, and
> things appear to be working quite well now.
email@example.com Monkeys do it better