[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-smp
Subject:    Re: Behavior of threaded programs
From:       "J.D. Bakker" <bakker () thorgal ! et ! tudelft ! nl>
Date:       1997-11-26 15:12:34
[Download RAW message or body]

>I have been working on a multi-threaded genetics simulation using
>linux-threads
<snip>
>  A second, related problem is the use of the rand() function by this
>program.
>I quickly learned that access to the rand function had to be protected by a
>mutex because of the static variables used in this function.  Is there an easy
>way of splitting access to this function across threads?  I've thought of
>making four versions of rand, and then passing pointers to these to each
>thread
>(eg. thread[1] uses rand[1]), but this seems kludgy and nonportable.  Any
>other
>suggestions?

Two suggestions. If you're running with libc5 (I don't know about glibc),
try static linking. In our case the threaded program wouldn't exceed 100%
CPU usage when using the default dynamic linking method.

Second, DON'T use rand() for such simulations. Try the DES-based RNG from
the ubiquitous Numerical Recipes in C; this allows your threads to have
multiple independent RNGs, which is what you want for scaleability.

JDB.

"... I've seen Sun monitors on fire off the side of the multimedia lab.
 I've seen NTU lights glitter in the dark near the Mail Gate.
 All these things will be lost in time, like the root partition last week.
 Time... to die...". - Peter Gutmann in the scary devil monastery

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic