[Mono-devel-list] implementing the synchronized method a

Varga Zoltan vargaz at freemail.hu
Mon Apr 14 05:26:12 EDT 2003


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 ?

                      bye

                          Zoltan









More information about the Mono-devel-list mailing list