for the first problem, you've found a bug in the Racket CS thread scheduler (i.e., Racket BC behaves correctly in this case). Suspending a thread that is sleeping didn't prevent the thread from being woken up on its previous schedule. I've pushed a repair as commit 7a12b4ac93.
After fixing that bug and using `thread/suspend-to-kill`, the second part works as expected. But if `t1` is created with `thread`, the behavior you describe sounds right: `t2` cannot resume a thread that was created with `thread` and then terminated by a custodian. Thanks for the report! Matthew At Sat, 7 Nov 2020 15:26:17 -0800 (PST), Greg Rosenblatt wrote: > I'm experimenting with using custodians to manage threads (on Racket 7.8 > [cs]) and encountering behavior I don't understand. > > I start a looping thread `t1` under a new custodian `c1`. > > I then shutdown `c1` and expect `t1` to stop looping. If I started `t1` > with `thread` then this expectation is met. However, if I start it with > `thread/suspend-to-kill`, it continues looping even after `c1` is shut > down. Is this the correct behavior? > > Additionally, I later start a new thread `t2` under a new custodian `c2`, > which attempts to resume `t1` after the shutdown, using itself as a > benefactor. However, `t1` does not seem to resume. Is this the correct > behavior? > > Here is the code I'm working with: > > ``` > #lang racket > > (define c1 (make-custodian)) > (define c2 (make-custodian)) > (define t1 #f) > (define t2 #f) > > (parameterize ((current-custodian c1)) > ;(set! t1 (thread/suspend-to-kill ;; (custodian-shutdown-all c1) fails > to suspend this thread > (set! t1 (thread > (lambda () > (let loop () > (displayln "thread 1") > (sleep 2) > (loop)))))) > > (displayln "ENTER to continue") > (read-line) > > (custodian-shutdown-all c1) > > (displayln "ENTER to continue") > (read-line) > > (parameterize ((current-custodian c2)) > (set! t2 (thread > (lambda () > (thread-resume t1 (current-thread)) > (let loop () > (displayln "thread 2") > (sleep 2) > (loop)))))) > > (displayln "ENTER to continue") > (read-line) > > (custodian-shutdown-all c2) > > (displayln "ENTER to continue") > (read-line) > ``` > > -- > 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. > To view this discussion on the web visit > https://groups.google.com/d/msgid/racket-users/f844779f-9abd-46bd-987f-b2b3ca3d > 0925n%40googlegroups.com. -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/20201107174703.320%40sirmail.smtps.cs.utah.edu.