Threading 101

  • Thread starter Thread starter Yuk Tang
  • Start date Start date
Y

Yuk Tang

Is there a basic guide to threading online? Something that not only
talks about the syntax, but also the concept and ideas related to it.
I'm still used to the school of single-thread programming, and I'm
interested in this.
 
Yuk said:
Is there a basic guide to threading online? Something that not only
talks about the syntax, but also the concept and ideas related to it.
I'm still used to the school of single-thread programming, and I'm
interested in this.

Here is a good basic primer - but is in C#, so I hope that isn't a
hinderance.

http://www.yoda.arachsys.com/csharp/threads/

Don't let the C# scare you, because the actual concepts are pretty much
the same. There is lots of material on the web about threading. But,
I'm going to give you my advice as well :)

Avoid it if at all possilbe. If it can't be avoided - keep your
threading model as simple as possible and try to keep the shared
resources to a minimum. If you can, using the built in thread pool and
asyncrounous method calls (via delagates) is the cleanest. Threading
is a tool, but it is a dangerous one if not done correctly - and it is
realitively hard to get right (plus, it can sometimes make debugging
problems much trickier). Anyway, good luck :)
 
Tom
Avoid it if at all possilbe. If it can't be avoided - keep your
threading model as simple as possible and try to keep the shared
resources to a minimum. If you can, using the built in thread pool and
asyncrounous method calls (via delagates) is the cleanest. Threading
is a tool, but it is a dangerous one if not done correctly - and it is
realitively hard to get right (plus, it can sometimes make debugging
problems much trickier). Anyway, good luck :)
And to add something for Yuk to your messages so if you agree you can add
that next time as well. It makes maintainability mostly a lot more
difficult.

Cor
 
Cor said:
Tom
And to add something for Yuk to your messages so if you agree you can add
that next time as well. It makes maintainability mostly a lot more
difficult.

Cor

Very true...
 
Tom Shelton said:
Here is a good basic primer - but is in C#, so I hope that isn't a
hinderance.

http://www.yoda.arachsys.com/csharp/threads/

Don't let the C# scare you, because the actual concepts are pretty
much the same. There is lots of material on the web about
threading. But, I'm going to give you my advice as well :)

Avoid it if at all possilbe.

Thanks. So I'm following good programming practice after all, if
only through ignorance. Now if that were a straightforward and
consistent equation, I'm sure I'd be the best programmer in the
world.

I originally wanted to set several tasks going, and deal with
timeouts as they come. Now following your advice, I'm going the
linear route with checks at crucial points. This is also good
practice in forcing me to build objects a part at a time, testing
those parts before integrating them into the main object, then
testing the whole object before integrating into a larger system.
 
Threading is useful if you have several different tasks that don't depend on
each other (very much). In this type of situation, the synchronization and
debugging issues aren't that difficult. Hoever, don't thread simply to
thread as this makes your debugging harder as well as forcing the system to
work harder. Remember, each thread requires system resources.

Still, you should learn how to handle and debug multi-threaded applications
as a lot of the .NET asynchronous callbacks are really executed on seperate
threads from your main application thread.

Mike Ober.
 
Back
Top