Thread Synchronization and method parameters

  • Thread starter Thread starter DaTurk
  • Start date Start date
D

DaTurk

This is probably a very simple question but I just want to make sure.
If I have three threads, all of which use their own class scope copy
of an object. Now, say I reuse this object for each iteration in each
thread, so I have to clean it. I have one method that takes in as an
argument one of these objects and zero's out the needed fields. I
don't need to lock this method right? Each thread will have it's own
copy, and because they're using their own variable it won't make a
difference? Am I good on this?
 
The way you describe it, it should be fine,. As long as each instance
is private to a single thread, then yes: you're pretty-much good to
go. If the threads are started with an anonymous method, you might
have to watch out for captured variables; ditto any static fields
(although a static emthod that doesn't share state is fine); and there
are a few other gotchas in complex scenarieos - but in the general
case it sounds fine.

Marc
 
The way you describe it, it should be fine,. As long as each instance
is private to a single thread, then yes: you're pretty-much good to
go. If the threads are started with an anonymous method, you might
have to watch out for captured variables; ditto any static fields
(although a static emthod that doesn't share state is fine); and there
are a few other gotchas in complex scenarieos - but in the general
case it sounds fine.

Marc

THanks yeah, I thought it would be OK. The threads are actually all
coming from async callbacks
from who knows where. But I figured I would take advantage of the
events and do some work on their threads since I'm not concerned with
bogging them down. But yes, all three instances are slotted for use
by only one thread.
 
Back
Top