On 1-Sep-09, at 1:58 PM, David St-Hilaire wrote:
Hi all!
I address this message to Marc, but I thought it might interest others so I cc'ed it to the gambit list ;).
What is the difference between the undocumented thread-interrupt! and thread-suspend! functions? Is it possible to retrieve an interrupted thread's continuation?
Basically I want to know if its possible to do something like:
(let ((t (make-thread (lambda () (let loop ((i 0)) (write 'o_O) (loop (+ i 1))))))) (thread-start! t) (thread-sleep! 0.5) (thread-interrupt!/suspend! t) (let ((k (get-the-continuation t))) (continuation-graft k (lambda (r) i))))
I don't know if this pseudo code is clear enough to illustrate my needs? I'd like to stop another thread and use continuation-graft to execute some code on it's stack.
How about:
(thread-interrupt t (lambda () ...))
The thunk will be executed by thread t, in the middle of its execution (in other words thread t is interrupted and made to run the thunk within the thread's continuation).
For example:
% gsi Gambit v4.5.1
(define t (thread-start!
(make-thread (lambda () (let ((n 0)) (let loop () (set! n (+ n 1)) (loop)))))))
(thread-interrupt!
t (lambda () (continuation-capture (lambda (c) (display-continuation-backtrace c (repl-output-port) #t #t)))))
0 ##thread-interrupt!
1 loop (console)@1:76 (begin (set! n (+ n 1)) (... loop = (lambda () (set! n (+ n 1)) (loop)) n = 27001012 2 ##thread-start-action! ,q
Marc