Subj : Re: threads do not get cpa To : comp.programming.threads,comp.sys.sgi.misc From : steve Date : Sun Aug 07 2005 11:59 pm In article <3lmrhmF133a4fU2@uni-berlin.de>, Patrick TJ McPhee wrote: >In article <1123428099.078544.129690@g49g2000cwa.googlegroups.com>, > wrote: > >% I also noticed another oddity: When I run my program with more threads >% it's slower than with just a single one, e.g.: > >Perhaps you spend more time contending for stderr and CurrentQuery than >you spend performing calculations. Try saving up the output in a >(pre-allocated) buffer and spitting it out in one go at thread exit >time, and pre-allocating the queries (i.e., have each thread step through >the list in steps of nthreads, rather than contending for a mutex after >each query. Also note that some implementations of drand48() require a mutex to protect the internal state of the random number generator. Others have the generator per-thread, but there's not any easy way to tell the difference. You might want to do your own implementation of drand48() that takes a context pointer, and have separate contexts for each thread. Or just come up with some other kind of work to do that is less likely to have an internal mutex. -- Steve Watt KD6GGD PP-ASEL-IA ICBM: 121W 56' 57.8" / 37N 20' 14.9" Internet: steve @ Watt.COM Whois: SW32 Free time? There's no such thing. It just comes in varying prices... .