Re: multi threading in C#
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Wed, 23 May 2007 23:42:18 -0700
On Wed, 23 May 2007 23:27:21 -0700, Jon Skeet [C# MVP] <skeet@xxxxxxxxx> wrote:
For example, instead of using "listLock" for the lock() and Monitor
methods, why not just use the "queue" instance?
If you lock on a reference that only you have access to, that
guarantees that no-one else can screw things up by locking on it
themselves.
Okay, the way I read that is that in the "listLock" versus "queue" reference example, "listLock" is the reference only you have access to, and the implication is that "queue" is a reference that others have access to.
Uh. Maybe I'm missing something, but...if you lock on a reference that only you have access to, but the object you're protecting is visible to others, doesn't that also mean that an alternate way for someone else to screw things up is by accessing the object *without* locking it?
It seems to me that if you've got an object that needs locking, and it somehow becomes accessible to outside code not guaranteed to obey the correct locking semantics, you've got problems one way or the other. Either the outside code locks it when you don't want it to, or it doesn't lock it when it ought to.
Isn't the correct solution to actually hide the object that needs locking from other code? That way the other code can't screw with it one way or the other.
I feel like something just went over my head, but I'm not sure what it is.
Pete
.
- Follow-Ups:
- Re: multi threading in C#
- From: Christof Nordiek
- Re: multi threading in C#
- From: Jon Skeet [C# MVP]
- Re: multi threading in C#
- References:
- Re: multi threading in C#
- From: Jon Skeet [C# MVP]
- Re: multi threading in C#
- From: Peter Duniho
- Re: multi threading in C#
- From: Jon Skeet [C# MVP]
- Re: multi threading in C#
- Prev by Date: Re: Conversion between collection interface types
- Next by Date: Re: How do I stop my software from getting cracked?
- Previous by thread: Re: multi threading in C#
- Next by thread: Re: multi threading in C#
- Index(es):
Relevant Pages
|