Re: SyncLock (Lock)

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



As you know, you can use any object as long as you always use the same
object. You last question is interesting. A lot of times your code and
contained collections change, rename, etc. At least for me, sometimes it is
just easier to define "private readonly object syncRoot = new object()"
upfront and know it will always be your syncRoot regardless of changes to
collections. Also, sometime you may have finer grain locking going on. So
you may be locking on a collection for a different reason. However, there
is nothing wrong with locking on your list object if that is the only lock
you need and your never replace your list object with another latter in your
program. What every it is - make it readonly!

--
William Stacey [C# MVP]

"Steven Spencer (Spinalogic)" <Spence-Spinalogic@xxxxxxxxxxxxxxxx> wrote in
message news:u1YoRhqOHHA.4376@xxxxxxxxxxxxxxxxxxxxxxx
| Hey guys.
|
| I come from a Java background and I'm familiar with monitors in java.
|
| I ahve been reading about the .net monitors, including the Lock loops, and
I
| came across a question.
|
| In most .net examples, there is a specific object (usually just of type
| object) upon which the CLR creates the monitor and it is this object is
used
| to ensure no concurrency.
|
| For instance if I was using something in the collections class, in java I
| would just lock on the queue/list/array/map etc to ensure thread safe
| access. Why is it that the majority of examples use a separate object?
|
|


.



Relevant Pages

  • Re: Suggestion for C#
    ... time and you should just use whatever locking mechanism you and your team ... actually end up with alot of lock contention as a result. ... Monitors work very well. ... ReaderWriterLocks, and things improved dramatically. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: SyncLock (Lock)
    ... the CLR itself is the one who controls the monitor, I believe that the java ... hence the introduction of monitors. ... why you *Shouldn't obtain an object lock on a variable within your code. ...
    (microsoft.public.dotnet.framework)
  • Re: using clustered index to optimize inserts ...
    ... I will try to explain locking in terms of Sybase docs... ... Allpages Locking: Allpages locking locks both data pages and index ... the data page is locked with an exclusive lock. ... Clustered Index: The datarows will be arranged as per the clustered ...
    (comp.databases.sybase)
  • Re: [PATCH 17/18] fs: icache remove inode_lock
    ... If you understand inode locking today, ... can understand the inode scaling series quite easily. ... filesystems to lock down the object without taking a global ... Per-zone is problematic. ...
    (Linux-Kernel)
  • Re: CSingleLock - known behaviour?
    ... It is better to design code that doesn't require locking. ... If you don't need the resource, don't lock it. ... magnitude less efficient, than locking once. ...
    (microsoft.public.vc.mfc)