Re: multi threading in C#
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Wed, 23 May 2007 16:58:11 -0700
On Wed, 23 May 2007 15:08:33 -0700, Jon Skeet [C# MVP] <skeet@xxxxxxxxx> wrote:
It sounds like you want a producer/consumer queue, or something like
it. See the second half of this page:
http://pobox.com/~skeet/csharp/threads/deadlocks.shtml
By the way, as long as we're on the topic, there's been something I've been curious about for awhile. I see in your example code, and I've seen this elsewhere as well, the creation of a new, base object instance for use as a locking object. I am curious what the point of that is, as compared to simply acquiring a lock on the object you are trying to synchronize access to.
For example, instead of using "listLock" for the lock() and Monitor methods, why not just use the "queue" instance?
The only thing that comes to mind is that in some cases, you may have an object where only certain parts of it need to be synchronized, but those parts may still be more than a single object within the larger object. In that case, having a dedicated object instance for locking allows for separation of the locking semantics from the actual implementation.
But otherwise? Are there other good reasons for doing it that way, or is it just a matter of being consistent since you would need do it that way sometimes?
Thanks,
Pete
.
- Follow-Ups:
- Re: multi threading in C#
- From: Chris Mullins [MVP]
- Re: multi threading in C#
- From: Jon Skeet [C# MVP]
- Re: multi threading in C#
- From: Moty Michaely
- Re: multi threading in C#
- References:
- Re: multi threading in C#
- From: Jon Skeet [C# MVP]
- Re: multi threading in C#
- Prev by Date: Re: multi threading in C#
- Next by Date: Re: Identifying an image type.
- Previous by thread: Re: multi threading in C#
- Next by thread: Re: multi threading in C#
- Index(es):
Relevant Pages
|
Loading