Re: Peculiar rand() case and threads
On Mar 2, 9:58 am, "ds" <junkmailav...@yahoo.com> wrote:
thanks for the reply. My question is more related to rand() rather
than threads ;-) and whether there is some access function. Apparently
there is rand_r() which is reentrant, but it does not yield the same
sequence (or I do not know how to make it do so...). Thanks a lot!!!
It's still intimately tied to threading -- if you reduce it to a
single-threaded case, there's no problem. I'd suggest you ask on
comp.programming.threads or a newsgroup for your OS or threading
library.
<OT>
Re-reading your original post, I take it that you want two threads to
use the random number generator simultaneously but without getting
different results. So if the random sequence is { 2, 5, 3, 1 }, you
want both threads to get this sequence in the exact same order (rather
than thread 1 seeing, say, { 2, 3 } and thread 2 seeing { 5, 1 } or
something). If so, I think you'll need to implement some sort of
queueing of the random numbers based on thread id or whatever. Ask for
more details on a more appropriate group, and you might get a more
insightful response.
</OT>
Cheers! --M