changeset 1933:8e6e3d9cea22

RAND_bytes isn't thread-safe, so wrap it with a lock
author Adam Chlipala <adam@chlipala.net>
date Wed, 11 Dec 2013 18:54:42 -0500
parents 98895243b5b6
children 420d129c4174
files src/c/urweb.c
diffstat 1 files changed, 4 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/c/urweb.c	Wed Dec 11 18:22:10 2013 -0500
+++ b/src/c/urweb.c	Wed Dec 11 18:54:42 2013 -0500
@@ -4023,9 +4023,13 @@
   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);