Re: SyncLock (Lock)
- From: "William Stacey [C# MVP]" <william.stacey@xxxxxxxxx>
- Date: Wed, 17 Jan 2007 21:45:42 -0500
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?
|
|
.
- Follow-Ups:
- Re: SyncLock (Lock)
- From: Steven Spencer \(Spinalogic\)
- Re: SyncLock (Lock)
- References:
- SyncLock (Lock)
- From: Steven Spencer \(Spinalogic\)
- SyncLock (Lock)
- Prev by Date: SyncLock (Lock)
- Next by Date: Re: How to determin if called by Web or Windows app
- Previous by thread: SyncLock (Lock)
- Next by thread: Re: SyncLock (Lock)
- Index(es):
Relevant Pages
|