mark kaplun wrote:
I have a multi threaded aplication. Should I make all my objects threadsafe
or just those which are really being accessed from different threads? what
are the pros and cons?. Any clue is appriciated.

Thanks,
  Mark.



my advice is to carefully select a minimal number of objects which need to be accessed by more than one thread and minimize the number of entry points into those objects that can be called on more than one thread. this helps you focus on getting the thread safety right in exactly/only the places where you know you need it. don't go overboard on trying to make everything threadsafe. it probably isn't worth it.

also, if you're moving a process onto a background thread, then try to separate the objects which must live on that thread from the objects that live on other threads. maybe have only one object that can be touched by both threads. let it be an object that delegates between objects on the two threads. a simple, focused, deliberate MT design is much better than one that tries to be multithreaded in general.

an event queue is also a great thread synchronization tool. it can help you keep separate the objects living on different threads.

darin




Reply via email to