Date: Thu, 3 Dec 2020 09:33:57 +0200 From: Andriy Gapon <avg@FreeBSD.org> To: cem@freebsd.org Cc: FreeBSD Current <freebsd-current@freebsd.org> Subject: Re: rand() is racy in multi-threaded programs? Message-ID: <22f5dfc1-c709-6911-b8b0-121e4c40affc@FreeBSD.org> In-Reply-To: <CAG6CVpXdrivsAk45dDKtk_0M3wuZ-WkdBz1HWHtr2GwRa6v78Q@mail.gmail.com> References: <5b827768-eb46-07f3-5b44-49627779786e@FreeBSD.org> <CAG6CVpXdrivsAk45dDKtk_0M3wuZ-WkdBz1HWHtr2GwRa6v78Q@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 03/12/2020 01:20, Conrad Meyer wrote: > Hi Andriy, > > Rand(3) is explicitly unsafe to use from concurrent threads without some > external serialization, even after initialization. I’d suggest using a different > API. Conrad, thank you! Just want to check, unsafe in terms of bogus results (with respect to randomness) or unsafe as in may crash? > On Wed, Dec 2, 2020 at 13:53 Andriy Gapon <avg@freebsd.org > <mailto:avg@freebsd.org>> wrote: > > > Specifically, concurrent "first" calls to rand(). > There can be a moment when rand3_state is allocated but not completely set up > with initstate_r(). > Is this a known / documented issue? > Should we try to do better? > > P.S. > I am seeing this issue from time to time when running ztest program (from ZFS). > I guess that it uses rand() just because that's what OpenZFS did / does on > illumos and Linux. > > P.P.S. > Just realized that the problem can be relatively recent. > https://svnweb.freebsd.org/base?view=revision&revision=357382 > > -- > Andriy Gapon > -- Andriy Gapon
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?22f5dfc1-c709-6911-b8b0-121e4c40affc>