rand() is racy in multi-threaded programs?

From: Andriy Gapon <avg_at_FreeBSD.org>
Date: Wed, 2 Dec 2020 23:53:41 +0200
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
Received on Wed Dec 02 2020 - 20:53:46 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:26 UTC