Serialize access to the population-of-1d-tables.
authorMatt Birkholz <puck@birchwood-abbey.net>
Wed, 1 Jul 2015 14:34:59 +0000 (07:34 -0700)
committerMatt Birkholz <puck@birchwood-abbey.net>
Mon, 17 Aug 2015 23:52:59 +0000 (16:52 -0700)
Allow create-thread to be run by multiple threads concurrently while
still accessing the population-of-1d-tables serially.

src/runtime/prop1d.scm
src/runtime/runtime.pkg
src/runtime/thread.scm

index 223c1e9f4bea7d60d84b2a9aed844b91ca30a6be..e4e9e360fa5b52865ff908348794d888568ce4fe 100644 (file)
@@ -30,8 +30,8 @@ USA.
 (declare (usual-integrations))
 \f
 (define (initialize-package!)
-  (set! population-of-1d-tables (make-population/unsafe))
-  (add-secondary-gc-daemon! gc-1d-tables!))
+  (set! population-of-1d-tables (make-serial-population/unsafe))
+  (add-secondary-gc-daemon! clean-1d-tables!))
 
 (define (initialize-unparser!)
   (unparser/set-tagged-pair-method! 1d-table-tag
@@ -39,10 +39,15 @@ USA.
 
 (define population-of-1d-tables)
 
-(define (gc-1d-tables!)
-  (map-over-population! population-of-1d-tables 1d-table/clean!))
+(define (clean-1d-tables!)
+  (for-each-inhabitant population-of-1d-tables 1d-table/clean!))
 
 (define (make-1d-table)
+  (let ((table (list 1d-table-tag)))
+    (add-to-population! population-of-1d-tables table)
+    table))
+
+(define (make-1d-table/unsafe)
   (let ((table (list 1d-table-tag)))
     (add-to-population!/unsafe population-of-1d-tables table)
     table))
index e8263956decea38316919cde7850a10acd847797..260d23022683261764df03a31dbe5d239705db4b 100644 (file)
@@ -1131,7 +1131,7 @@ USA.
          1d-table?
          make-1d-table)
   (import (runtime population)
-         make-population/unsafe
+         make-serial-population/unsafe
          add-to-population!/unsafe)
   (initialization (initialize-package!)))
 
@@ -5094,6 +5094,8 @@ USA.
   (import (runtime population)
          add-to-population!/unsafe
          make-population/unsafe)
+  (import (runtime 1d-property)
+         make-1d-table/unsafe)
   (export (runtime interrupt-handler)
          thread-timer-interrupt-handler)
   (export (runtime primitive-io)
index 6074bbb4813312f63acf9fb562663b6f192f2720..13d2eed7d283b7468fdf01ef9097eb05aea9e85e 100644 (file)
@@ -33,7 +33,7 @@ USA.
 (define enable-smp? #f)
 \f
 (define-structure (thread
-                  (constructor %make-thread ())
+                  (constructor %make-thread (properties))
                   (conc-name thread/))
   (execution-state 'RUNNING)
   ;; One of:
@@ -82,7 +82,7 @@ USA.
   ;; List of mutexes that this thread owns or is waiting to own.  Used
   ;; to disassociate the thread from those mutexes when it is exited.
 
-  (properties (make-1d-table) read-only #t))
+  (properties #f read-only #t))
 
 (define-integrable (guarantee-thread thread procedure)
   (if (not (thread? thread))
@@ -110,7 +110,7 @@ USA.
   (set! timer-records #f)
   (set! timer-interval 100)
   (reset-threads-low!)
-  (let ((first (%make-thread)))
+  (let ((first (%make-thread (make-1d-table/unsafe))))
     (set-thread/exit-value! first detached-thread-marker)
     (set-thread/root-state-point! first
                                  (current-state-point state-space:local))
@@ -158,7 +158,7 @@ USA.
   unspecific)
 
 (define (make-thread continuation)
-  (let ((thread (%make-thread)))
+  (let ((thread (%make-thread (make-1d-table))))
     (set-thread/continuation! thread continuation)
     (set-thread/root-state-point! thread
                                  (current-state-point state-space:local))