[Mono-list] Mono embedding with threads + multiple domains

Robert Jordan robertj at gmx.net
Thu Feb 28 18:07:14 UTC 2013


Roberto,

On 28.02.2013 16:22, Roberto De Ioris wrote:
>>> the plugin is already in good shape but now i would like to add
> multi-domains support (currently you can load multiple applications but
> all in the same mono domain)
>>
>> ApplicationHost.CreateApplicationHost is already creating its
>> own app domain.
>
>>
>> I did not test your code, but it looks like you don't take
>> this into account. All icalls seem to allocate objects from
>> the main app domain, but you're expected to allocate them
>> in the current domain (see mono_domain_get ()).
>
>
> Absolutely, i was sure i need to manually manage domains.
>
> So, when i create a new ApplicationHost with
>
> ApplicationHost.CreateApplicationHost
>
> i am effectively creating a new domain and when i call
>
> HttpRuntime.ProcessRequest
>
> i am effectively moving to the corresponding domain.


The domain is automatically switched at this line:

https://github.com/unbit/uwsgi/blob/master/plugins/mono/uwsgi.cs#L130

"appHost" is actually a proxy of the real object.

> If it is right how i need to register my pthreads in the multi-domain
> system ? Currently (as you have noted) i attach pthreads (to the main
> domain) when they start.

Your code is alright as it is, because you don't need to attach
threads to a specific domain.

mono_thread_attach (mono_domain_get());

is sufficient.

As a rule of thumb, whenever the Mono API is expecting a
domain argument, mono_domain_get () is almost always right.

Robert





More information about the Mono-list mailing list