summaryrefslogtreecommitdiff
path: root/src/c/urweb.c
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2013-12-11 18:54:42 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2013-12-11 18:54:42 -0500
commitbc4cdf7f4a995846125917ac0abb1a67bfd81fca (patch)
tree6e276b0cdd07416e468a8b43bb03e9fb5f76cfaa /src/c/urweb.c
parentd7c4817af0c7f4ea2ed30b4a34408f2f92e9e979 (diff)
RAND_bytes isn't thread-safe, so wrap it with a lock
Diffstat (limited to 'src/c/urweb.c')
-rw-r--r--src/c/urweb.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 1201b09b..1c66e9e8 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -4023,9 +4023,13 @@ uw_Basis_unit uw_Basis_debug(uw_context ctx, uw_Basis_string s) {
return uw_unit_v;
}
+static pthread_mutex_t rand_mutex = PTHREAD_MUTEX_INITIALIZER;
+
uw_Basis_int uw_Basis_rand(uw_context ctx) {
uw_Basis_int ret;
+ pthread_mutex_lock(&rand_mutex);
int r = RAND_bytes((unsigned char *)&ret, sizeof ret);
+ pthread_mutex_unlock(&rand_mutex);
if (r)
return abs(ret);