On Sat, 24 Jul 2010 10:16:09 +0200 richard wrote:
> 
> And, while I'm here, a couple of relevant guidelines to writing
> multi-threaded code:

There's another that you've missed:

 - Use as few threads as possible.

Basically, threads add overhead. You get benefit only up to the point where 
there are as many threads as you have independent CPU cores. Beyond that your 
performance drops off as compared to a well structured idle loop, and the 
readability isn't noticeably better either.

If you want to sum the results of foo(x[i]) over an array of N elements, where 
N is large and foo() is simple, I wouldn't use threads. If this is a background 
task and you want GTK to remain responsive, I would launch exactly ONE thread 
to do the summing. If foo() is complex, I would split N into M ranges, where M 
is roughly the number of CPU cores you expect to have, and launch M threads. 
Only if N is approximately equal to M would I take the approach being discussed 
here.

Rob
_______________________________________________
gtk-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-list

Reply via email to