[Mono-devel-list] implementing the synchronized method a
dietmar
dietmar at ximian.com
Mon Apr 14 05:40:34 EDT 2003
On Mon, 2003-04-14 at 11:26, Varga Zoltan wrote:
> Paolo Molaro <lupus at ximian.com> írta:
>
> > On 04/12/03 Varga Zoltan wrote:
> > > I would like to implement the 'synchronized' method
> > > attribute in the
> > > runtime. I thought about using the wrapper facility for
> > > this, i.e. creating
> > > a synchronized wrapper for the method which would call the
> > > non-synchronized version. Is this a good idea?
> >
> > I don't think using a wrapper would buy you anything.
> > The best way, IMO, is to insert the calls to
> > mono_monitor_enter/mono_monitor_leave in mono_method_to_ir().
> >
>
> Hi,
>
> I suggested using a wrapper because it reuses existing
> code, i.e.
> the wrapper would contain IL code similar to the code
> generated by
> mcs for this statement:
> lock (this) {
> <CALL ORIGINAL METHOD>
> }
>
> This has the advantage that the exception handling stuff
> comes for
> free, i.e. there is no need to save the location of the this
> pointer, no
> need to obtain its value at runtime etc. The only change
> needed in the
> runtime is the substitution of the wrapper in place of the
> original method
> in the appropriate place. What's the problem with this
> approach ?
The only disadvantage I see is that it uses additional memory for the IL
wrappers, but I thing this does not really count.
- Dietmar
More information about the Mono-devel-list
mailing list