471,350 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Does MethodImpl Synchronized atribute is like lock(this) ?

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.

Nov 30 '05 #1
2 3456
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/de...netchapt05.asp
HTH

Stoitcho Goutsev (100) [C# MVP]
"yaron" <ya***@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
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.

Nov 30 '05 #2
yaron wrote:
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.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Nov 30 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.