Any objections if I check in some thread safety changes to the lower
levels, such as the attached patch ?

I don't think there's going to be a multi-threaded pspp for production
use any time soon, but I've been doing some experiments in order to
find out what some of the issues are.

J'


-- 
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://pgp.mit.edu or any PGP keyserver for public key.


diff --git a/Smake b/Smake
index f6ab964..8af2c10 100644
--- a/Smake
+++ b/Smake
@@ -37,6 +37,7 @@ GNULIB_MODULES = \
 	intprops \
 	inttostr \
 	localcharset \
+	lock \
         mbchar \
 	memcasecmp \
 	memchr \
diff --git a/src/data/value-labels.c b/src/data/value-labels.c
index 9f6113b..58e5b8c 100644
--- a/src/data/value-labels.c
+++ b/src/data/value-labels.c
@@ -27,6 +27,7 @@
 #include <libpspp/hash.h>
 #include <libpspp/message.h>
 #include <libpspp/str.h>
+#include <glthread/lock.h>
 
 #include "xalloc.h"
 
@@ -413,6 +414,7 @@ static hsh_free_func free_atom;
 
 /* Hash table of atoms. */
 static struct hsh_table *atoms;
+gl_once_define (static, atom_once);
 
 static void
 destroy_atoms (void)
@@ -420,6 +422,14 @@ destroy_atoms (void)
   hsh_destroy (atoms);
 }
 
+static void
+initialize_atom_hash (void)
+{
+  atoms = hsh_create (8, compare_atoms, hash_atom, free_atom, NULL);
+  atexit (destroy_atoms);
+}
+
+
 /* Creates and returns an atom for STRING. */
 static struct atom *
 atom_create (const char *string)
@@ -429,11 +439,7 @@ atom_create (const char *string)
 
   assert (string != NULL);
 
-  if (atoms == NULL)
-    {
-      atoms = hsh_create (8, compare_atoms, hash_atom, free_atom, NULL);
-      atexit (destroy_atoms);
-    }
+  gl_once (atom_once, initialize_atom_hash);
 
   a.string = (char *) string;
   app = hsh_probe (atoms, &a);
diff --git a/src/libpspp/pool.c b/src/libpspp/pool.c
index 88d3535..17f8c07 100644
--- a/src/libpspp/pool.c
+++ b/src/libpspp/pool.c
@@ -19,6 +19,7 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <libpspp/assertion.h>
+#include <glthread/lock.h>
 #include "message.h"
 #include "str.h"
 
@@ -121,6 +122,7 @@ union align
 
 /* Serial number used to keep track of gizmos for mark/release. */
 static long serial = 0;
+gl_lock_define_initialized (static, serial_mutex);
 
 /* Prototypes. */
 static void add_gizmo (struct pool *, struct pool_gizmo *);
@@ -898,7 +900,9 @@ add_gizmo (struct pool *pool, struct pool_gizmo *gizmo)
     pool->gizmos->prev = gizmo;
   pool->gizmos = gizmo;
 
+  glthread_lock_lock (&serial_mutex);
   gizmo->serial = serial++;
+  glthread_lock_unlock (&serial_mutex);
 
   check_gizmo (pool, gizmo);
 }

Attachment: signature.asc
Description: Digital signature

_______________________________________________
pspp-dev mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/pspp-dev

Reply via email to