[gegl] c2g|stress: stop race in initializing array of randoms



commit 591df0425e49293ac8f5c5bc5c2eebc473b9de20
Author: Øyvind Kolås <pippin gimp org>
Date:   Sat May 25 16:43:33 2019 +0200

    c2g|stress: stop race in initializing array of randoms
    
    From a usage point of view this fixes c2g and stress multi-threaded, the
    results remain non-reproducable, issue #125 is not fully fixed though -
    since now the random numbers used are still racy when multi-threaded.

 operations/common/envelopes.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/operations/common/envelopes.h b/operations/common/envelopes.h
index f23d7a0ec..9ae5943a3 100644
--- a/operations/common/envelopes.h
+++ b/operations/common/envelopes.h
@@ -20,20 +20,19 @@
 static gfloat   lut_cos[ANGLE_PRIME];
 static gfloat   lut_sin[ANGLE_PRIME];
 static gfloat   radiuses[RADIUS_PRIME];
-static gdouble  luts_computed = 0.0;
+static gint     luts_computed = 0;
 static gint     angle_no=0;
 static gint     radius_no=0;
 
-static void compute_luts(gdouble rgamma)
+static void compute_luts(gint rgamma)
 {
   gint i;
   GRand *rand;
   gfloat golden_angle = G_PI * (3-sqrt(5.0)); /* http://en.wikipedia.org/wiki/Golden_angle */
   gfloat angle = 0.0;
 
-  if (luts_computed==rgamma)
+  if (g_atomic_int_get (&luts_computed)==rgamma)
     return;
-  luts_computed = rgamma;
   rand = g_rand_new();
 
   for (i=0;i<ANGLE_PRIME;i++)
@@ -48,6 +47,7 @@ static void compute_luts(gdouble rgamma)
     }
 
   g_rand_free(rand);
+  g_atomic_int_set (&luts_computed, rgamma);
 
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]