Re: static classes & threading
- From: Frank Rizzo <none@xxxxxxxx>
- Date: Tue, 19 Apr 2005 14:00:42 -0700
Bruce Wood wrote:
I think that your confusion (and ours) arises because you haven't stated where you are storing your data. Threading problems don't crop up based on whether you have static or instance methods. They crop up based on whether the threads share data, or state.
If DoSomeTask creates a connection _and then stores that connection in a static variable_ that is visible to other threads, then you'll have contention problems and will have to introduce a lock. If, however, DoSomeTask creates a connection and puts the reference to it in a local variable (which would be on the stack), there is no interaction between threads, because each thread has its own stack.
If your static class has static state as well, then you have to worry about locks. If it has no state, there should be no threading problems and no waiting.
That's correct - I am confused by what the threads actually use.
Let me give you an example. Let's say I have a static transaction object. It is used by a non-static class method to insert some data. If 2 threads were to have a go at this non-static method, would they both use the static transaction object? And as a result, would there be contention for that static transaction object?
Tbanks .
- Follow-Ups:
- Re: static classes & threading
- From: Bruce Wood
- Re: static classes & threading
- References:
- static classes & threading
- From: Frank Rizzo
- Re: static classes & threading
- From: Gabriel Lozano-Morán
- Re: static classes & threading
- From: Frank Rizzo
- Re: static classes & threading
- From: Bruce Wood
- static classes & threading
- Prev by Date: Controls in a panel
- Next by Date: Re: TabControl how do get close tab [x] on tabcontrol ?
- Previous by thread: Re: static classes & threading
- Next by thread: Re: static classes & threading
- Index(es):