Does MethodImpl Synchronized atribute is like lock(this) ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Does MethodImpl Synchronized attribute is like lock(this) ?
i mean that a call to Monitor.PulseAll(this) from a Synchronized method will
trigger other thread that call to Monitor.Wait(this) ?

Thanks.
 
yaron,

Yes, MethodImpl Synchronized is implemented exactly like that it uses
lock(this) for the entire method. It can be easily tested. However I don't
see anywhere in the docs this documented so I don't know if it is a good
idea to build your code based on this presumption.

On the other hand the implementation is still the same in .NET 2.0.

Why you want to use MethodImp attribute? Why you don't use lock statements?
lock(this) is not always a good idea.

Take a look at this article it has some guidlines of how to use different
sync techniques.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenetchapt05.asp


HTH

Stoitcho Goutsev (100) [C# MVP]
 
yaron said:
Hi,

Does MethodImpl Synchronized attribute is like lock(this) ?
i mean that a call to Monitor.PulseAll(this) from a Synchronized method will
trigger other thread that call to Monitor.Wait(this) ?

Thanks.

Should be easy to test.
 
Back
Top