Re: Is Singleton collection of Singletons possible??
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 03/04/04
- Next message: Stoitcho Goutsev \(100\) [C# MVP]: "Re: To Stoicho... Re: Repost, Unanswered Hooking Problem..."
- Previous message: Mark: "format numeric to string - decimal places"
- In reply to: Daniel Billingsley: "Re: Is Singleton collection of Singletons possible??"
- Next in thread: Daniel Billingsley: "Re: Is Singleton collection of Singletons possible??"
- Reply: Daniel Billingsley: "Re: Is Singleton collection of Singletons possible??"
- Reply: Daniel Billingsley: "Re: Is Singleton collection of Singletons possible??"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 4 Mar 2004 21:38:38 -0000
Daniel Billingsley <dbillingsley@NO.durcon.SPAAMM.com> wrote:
> Well, of course. But for thread-safeness it's the 3rd step that is of
> significance. That is to say, setting aside my specific application, the
> problem is two threads attempting to add the same ID. I take "A Hashtable
> can support one writer and multiple readers concurrently. To support
> multiple writers, all operations must be done through this wrapper only." to
> mean the synchronized Hashtable itself wouldn't allow that, and I'd end up
> with an ArgumentException. How do you take it? (That's assuming I use the
> Add method which maybe is not the code you posted before as I recall.)
No, you wouldn't end up with an ArgumentException - you'd end up with
each call locking all other calls out until it completed.
> Now, that's not to say that using locking isn't better than dealing with the
> exceptions, if that's where you'll go next. I'll have to evaluate that. I
> just want to make sure I'm understanding these concepts correctly first
> though.
The problem is that if two different threads can both reach step 2, you
create more than one object for the same ID, which is usually a bad
move.
With threading, I always take the "simple is best" approach: while
you're dealing with shared data, take out a lock. I think people
generally believe that locks are more expensive than they really are.
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Stoitcho Goutsev \(100\) [C# MVP]: "Re: To Stoicho... Re: Repost, Unanswered Hooking Problem..."
- Previous message: Mark: "format numeric to string - decimal places"
- In reply to: Daniel Billingsley: "Re: Is Singleton collection of Singletons possible??"
- Next in thread: Daniel Billingsley: "Re: Is Singleton collection of Singletons possible??"
- Reply: Daniel Billingsley: "Re: Is Singleton collection of Singletons possible??"
- Reply: Daniel Billingsley: "Re: Is Singleton collection of Singletons possible??"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|