[m-dev.] Initialising the Mercury runtime in .NET

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Oct 14 01:52:15 AEST 2003


On 13-Oct-2003, Peter Ross <pro at missioncriticalit.com> wrote:
> On Tue, Oct 14, 2003 at 12:31:27AM +1000, Fergus Henderson wrote:
> > On 13-Oct-2003, Peter Ross <pro at missioncriticalit.com> wrote:
> > > Before one can use Mercury.NET, one must call io__init_state.
> > >
> > > Currently this is done by inserting the call to MR_init_runtime, which
> > > simply calls io__init_state but may at a later date do more, in the
> > > class constructor (.cctor) of the assembly containing main/2.  This is
> > > problematic if you want to use a Mercury.NET assembly as a library as
> > > then this routine isn't called.
> > 
> > It is problematic if you don't call it, yes.
> > 
> > There is a fairly straight-forward solution, however: call it.
>
> Yes, but the problem is that you only want to call it once because you
> don't want to be re-initialising the stream map and the globals,
> everytime you re-enter the library.
> 
> Of course we can add a new piece of code which just initialises the
> runtime with a test to make sure that it hasn't been done.

Yes, the simple solution to problems like these is to add a wrapper
which sets a boolean (or increments a reference count) to indicate
when the library has already been initialized, and to not re-initialize
it if it is already initialized.

> I was just trying to find a more elegant solution.

I think the solution mentioned above is quite adequate.

> > Currently phases 1 and 2 are done in the .cctors, and phase 3 is done
> > in main/2.
>
> To be precise, phase 3 is done as the last thing in the .cctor of the
> module containing main.

Thanks for the correction.

> As pointed out above ML_runtime_init will need to be modified to ensure
> that it isn't run twice.

Yes.

> I think it also needs to be made thread safe,
> for the cases where the Mercury library is used by say a COM+ component.

Yes.  Same thread safety issue arises for all the .cctors that we generate,
I think.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list