Re: Locking techniques
- From: "Jon Skeet [C# MVP]" <skeet@xxxxxxxxx>
- Date: 1 Dec 2005 04:36:30 -0800
Laura T. wrote:
> There is a MSR publication that seems to approve the use of lock(this) in
> many cases.
>
> http://research.microsoft.com/research/pubs/view.aspx?tr_id=921
Interesting that it doesn't really go into *why* that's being used
though - it seems to be used pretty much by default, ignoring the
possibility that other code will lock on the same reference.
I'm sure there are plenty of articles which use lock(this) - but there
are also articles which describe the pitfalls of such an approach.
Here's one by Jeffrey Richter:
http://msdn.microsoft.com/msdnmag/issues/03/01/NET/
Personally I think it was a mistake making all reference types have
monitors - although it's taken me a long time to come to that
conclusion. (I used to think it was a great idea, right back from when
I started Java programming.)
See http://www.pobox.com/~skeet/csharp/threads/alternative.shtml for a
view on how I would have preferred things to work - and an option for
coding that way instead of using plain "lock" statements.
Jon
.
- References:
- Locking techniques
- From: Laura T.
- Re: Locking techniques
- From: Adam Cooper
- Re: Locking techniques
- From: Michael S
- Re: Locking techniques
- From: Jon Skeet [C# MVP]
- Re: Locking techniques
- From: Laura T.
- Locking techniques
- Prev by Date: populating dropdown in datagrid
- Next by Date: Re: can we do fork() in c#
- Previous by thread: Re: Locking techniques
- Next by thread: making an http server
- Index(es):
Relevant Pages
|