Re: random() in multi-threaded pgbench

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Takahiro Itagaki <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: random() in multi-threaded pgbench
Date: 2009-12-11 20:27:47
Message-ID: 23213.1260563267@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Takahiro Itagaki <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp> writes:
> While testing the pgbench setshell command patch with -j option,
> I found all threads use the same sequence of random value.

Were they actually threads, or were you testing the code while it had
the broken configure script that didn't set ENABLE_THREAD_SAFETY?
I think you might have hit the same thing I just ran into, that in
a *non-threaded* build each subprocess will generate the same random
sequence.

> At first, I think we need to call srandom() in each thread,

Each sub-job I think.

> but the manual says we should use random_r() instead of random()
> on multi-threaded programs.
> http://www.kernel.org/doc/man-pages/online/pages/man3/random_r.3.html

It only says that you need those if you want an *independent* random
sequence for each thread. pgbench never had that before and I doubt
we need it now. In any case, the same page also says these are a
glibc-ism not a standard API, so we can't really rely on them.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2009-12-11 20:28:12 Re: Adding support for SE-Linux security
Previous Message Stephen Smalley 2009-12-11 20:25:19 Re: Adding support for SE-Linux security