The stomping on I was worried about would  happen at a lower-level as
I don't think that, in general, dynamic-require is thread-safe. After
all, it loads and runs arbitrary code, altho in this case it appears
to be a system level lack of thread safety? I'm still not completely
sure, but since you seem to be able to provoke the error, that
emboldens me to suggest you apply the diff below and see if it goes
away.

That diff is probably not what we'd want in the end, since it is too
much locking (we would want a namespace-specific lock not a global
one) but if the error does go away, that means that this is probably
the right place to put the lock in.

Robby

☕  git diff | cat
diff --git a/handin-server/private/reloadable.rkt
b/handin-server/private/reloadable.rkt
index 1055822..0089fcb 100644
--- a/handin-server/private/reloadable.rkt
+++ b/handin-server/private/reloadable.rkt
@@ -1,8 +1,33 @@
 #lang racket/base

 (require syntax/moddep "logger.rkt")
+(module mon racket/base
+  (define sema (make-semaphore 1))
+  (define-syntax-rule
+    (provide/monitor (id x ...))
+    (begin
+      (define -id
+        (let ([id (λ (x ...)
+                    (call-with-semaphore
+                     sema
+                     (λ () (id x ...))))])
+          id))
+      (provide (rename-out [-id id]))))
+  (provide provide/monitor))
+(require (submod "." mon))

-(provide reload-module)
+(module+ test
+  (module m racket/base
+    (require (submod ".." ".." mon))
+    (define (f x) (* 2 (g x)))
+    (define (g x) (+ x 1))
+    (provide/monitor (f x))
+    (provide/monitor (g x)))
+  (require (submod "." m) rackunit)
+  (check-equal? (g 2) 3)
+  (check-equal? (f 11) 24))
+
+(provide/monitor (reload-module modspec path))
 (define (reload-module modspec path)
   ;; the path argument is not needed (could use resolve-module-path here), but
   ;; its always known when this function is called
@@ -20,7 +45,7 @@

 ;; pulls out a value from a module, reloading the module if its source file was
 ;; modified
-(provide auto-reload-value)
+(provide/monitor (auto-reload-value modspec valname))
 (define module-times (make-hash))
 (define (auto-reload-value modspec valname)
   (define path0 (resolve-module-path modspec #f))
@@ -43,7 +68,7 @@
 ;; pulls out a procedure from a module, and returns a wrapped procedure that
 ;; automatically reloads the module if the file was changed whenever the
 ;; procedure is used
-(provide auto-reload-procedure)
+(provide/monitor (auto-reload-procedure x y))
 (define (auto-reload-procedure modspec procname)
   (let ([path (resolve-module-path modspec #f)] [date #f] [proc #f] [poll #f])
     (define (reload)
☕  [robby@gongguan] ~/git/exp/plt/extra-pkgs/handin
☕

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to