views:

90

answers:

2

I recently watching this video on Google Chrome with great interest. It explains that Google Chrome uses one thread for IO, one for opening files and one for intermodule communication.

I think I may be able to use something similar for my own - currently quite messy - application.

I wondered if there were any good articles on best-practices or patterns for such threaded divisions of tasks?

+4  A: 

Any time your application has tasks that can be divided into distinct groups, it's a candidate for multi-threading. Be warned that it's a dangerous game, though - for every article you can find about the advantages, there are two about getting bitten by a multi-threading implementation - it can create bugs that only occur in certain configurations (on the users computers), or worse, can't be duplicated in the debugger because the act of slowing down execution is enough to cause the bug to fail to appear (race conditions are notorious for this behavior).

That warning aside, multi-threading can be a huge boost to both the actual and the perceived performance of your application. These are .NET specific, but give a general primer explaining the advantages of background threads and keeping your UI responsive:

rwmnau
Yeah, threads are awful :p At least it seams I've never fully managed to "divide into distinct groups".What I really need is something similar to design patterns, just for threads. I think.
Thomas Ahle
The first like is somewhat helpful, but they are both very implementation specific, and not so much about "ideas". Do you know any articles about patterns for dividing and communication?
Thomas Ahle
Especially this idea from the movie - a communication thread - that has as task to send messages between other threads. I have never imagined a pattern like that before
Thomas Ahle
A: 

If you're using .NET, the ThreadPool class is a good starting point that manages some (but not all) of the subtleties of multi-threading for you.

See also the Threads and Threading topic on MSDN for a discussion of the pros and cons.

Andréas Saudemont