Bug #60197 random used in a multithreaded context

Submitted: 22 Feb 2011 7:48 Modified: 14 Apr 2011 10:37
Reporter: Guoliang Jin Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S5 (Performance)
Version:5.1.55 OS:Windows
Assigned to: CPU Architecture:Any

[22 Feb 2011 7:48] Guoliang Jin
Description:
In file mysql-5.1.55/client/mysqlslap.c:1864, random() is used in the multithreaded context run_task, according to the man page of the random function:
"This function should not be used in cases where multiple threads use random() and the behavior should be reproducible.  Use random_r(3) for that purpose.", so random_r should be used here.

How to repeat:
by reviewing the file mysql-5.1.55/client/mysqlslap.c
[27 Feb 2011 13:25] Shane Bester
I verify the fact that random() is used, and what the manpage says:
http://www.kernel.org/doc/man-pages/online/pages/man3/random.3.html\

However, mysqlslap doesn't use a constant seed to generate repeatable random numbers in multiple threads.  It just needs random numbers without being repeatable later.

/* Seed the random number generator if we will be using it. */
  if (auto_generate_sql)
    srandom((uint)time(NULL));

So if the only problem is not having repeatable sequences, is this really a bug at all?
[27 Feb 2011 20:31] Guoliang Jin
According to http://evanjones.ca/random-thread-safe.html, the reason that random() should not be used in multi-thread context on Linux is that rand() and random() acquire a mutex to ensure thread-safe on Linux, and this could over-synchronize the problem and may lead to performance issue, thus random_r() should be used instead.

Bug 38941 is a previous case related to random().

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.051 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.