Re: thread resource leaks if thread terminates with uncaught exception
Jens Thiele <[email protected]> Mon, 13 Jan 2025 07:34:39 +0100
| Newsgroups | gmane.lisp.scheme.gauche |
|---|---|
| Message-ID | <[email protected]> |
Shiro Kawai <[email protected]> writes: > I pushed a fix of pmap to ensure all worker threads are joined. Seems to > be working with simple manual tests. It's a bit difficult to write an > automated test for it, though. looking at: (define-method run-map ((mapper <fully-concurrent-mapper>) proc coll) (let ([unique (list #f)] [ts (map (^e (make-thread (^[] (proc e)))) coll)] [timeout (absolute-time (~ mapper'timeout))] [timeout-val (~ mapper'timeout-val)]) (%start-threads ts) (%with-wrapped-join (let1 join! (%make-joiner #f) (if timeout ($ map (^r (if (and (pair? r) (eq? (car r) unique)) (begin (thread-terminate! (cdr r)) timeout-val) r)) $ map (^t (join! t timeout (cons unique t))) ts) (map join! ts)))))) ) A difference to my "solution" is that you don't terminate all threads in case of an early error immediately, but maybe this is a good thing. I still wonder about the timeout case. But it looks like one doesn't have to join after a successful thread-terminate!. Then only a failing thread-terminate! case might cause a problem/"died a lonely death"? Jens