Jay Sprenkle wrote:
My advice to *all* programmers is to never use more than one thread
in the same address space.  I have never in 20 years worked on a
multiple threaded program that actually got all of the threading
issues right.  There are always subtle bugs that cause error that
are very difficult to reproduce and fix.  Multithreading is the
fastest road to buggy code that I know of.  Avoid it.  If you
absolutely, positively must have multiple threads of control, put
each thread in its own address space (make it a process.)


I second the motion!

I agree that threads have to be treated with caution. Locking must be used everywhere. Expect some difficult bugs. Protect your buffers etc...


But I think there is a valid place... For instance in event-driver programming. Programming a single thread to handle events without sticking on one event, can arguably be as hard and buggy as giving each event it's own thread. See Win95 :) This can be helped by using objects which have been designed to be thread safe. For instance, Java's excellent thread-safe hash-table. Threads also find a use where TCP/IP blocking may be encountered.

Also where a UI is used at the same time as some back-processing. Eg, downloading email on a slow link, whilst writing and sending another email. With a single thread, this would be extremely hard to program well.

I also note the performance gains which can be obtained from modern hyperthreaded CPU's.

But these are my opinions, and I have been programming a lot less than 20 years, as well as being new to this list, so ignore please my ramblings!

Ben

Reply via email to