Re: Locking techniques

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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

.



Relevant Pages

  • Re: SetPixel() / GetPixel() for Format64bppArgb in VB using LockBits
    ... A performance boost can probably be had if you only lock the one pixel of ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Historical operation of canals in Holland during the 1600s
    ... I had searched wikipedia but your link got me to articles I hadn't found. ... I've not found direct answers to my questions for Amsterdam but I have learned that canal and lock technology was very sophisticated by 1600. ... the operation is much different--there is no tidal swing at Amsterdam because the Zuiderzee is diked off and pumps are used to exchange water in the canals. ...
    (sci.geo.hydrology)
  • Test with 2 Users: Button value changes automatic
    ... I have a strange behaviour. ... with articles that have to be produced today or the ... Now it can be, that the planner has ... the possiblity to lock it with a button called "lock", ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Struct a lightweight class type having value based semantics?
    ... articles, and am confident I have a fair grasp of them. ... Jon Skeet wrote: ... Specifically Struct. ... value types and classes are reference types. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: My way to check if a progam is already running
    ... it updates article numbers and writes these immediately back to a config file. ... started or did something) and get the same articles again. ... If it has a counter in RAM, it also has a lock on the ...
    (comp.os.linux.development.apps)