1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

cancel-thread can take arguments

* doc/ref/api-scheduling.texi (Threads):
* module/ice-9/threads.scm (cancel-thread): Additional args to
  cancel-thread will be returned by the thread.
This commit is contained in:
Andy Wingo 2016-10-31 22:11:01 +01:00
parent 6bf9c65419
commit a7114ced5f
2 changed files with 9 additions and 7 deletions

View file

@ -112,12 +112,13 @@ If one or more threads are waiting to execute, calling yield forces an
immediate context switch to one of them. Otherwise, yield has no effect. immediate context switch to one of them. Otherwise, yield has no effect.
@end deffn @end deffn
@deffn {Scheme Procedure} cancel-thread thread @deffn {Scheme Procedure} cancel-thread thread . values
@deffnx {C Function} scm_cancel_thread (thread) @deffnx {C Function} scm_cancel_thread (thread)
Asynchronously interrupt @var{thread} and ask it to terminate. Asynchronously interrupt @var{thread} and ask it to terminate.
@code{dynamic-wind} post thunks will run, but throw handlers will not. @code{dynamic-wind} post thunks will run, but throw handlers will not.
If @var{thread} has already terminated or been signaled to terminate, If @var{thread} has already terminated or been signaled to terminate,
this function is a no-op. this function is a no-op. Calling @code{join-thread} on the thread will
return the given @var{values}, if the cancel succeeded.
Under this hood, thread cancellation uses @code{system-async-mark} and Under this hood, thread cancellation uses @code{system-async-mark} and
@code{abort-to-prompt}. @xref{Asyncs} for more on asynchronous @code{abort-to-prompt}. @xref{Asyncs} for more on asynchronous

View file

@ -88,16 +88,17 @@
(define cancel-tag (make-prompt-tag "cancel")) (define cancel-tag (make-prompt-tag "cancel"))
(define (cancel-thread thread) (define (cancel-thread thread . values)
"Asynchronously interrupt the target @var{thread} and ask it to "Asynchronously interrupt the target @var{thread} and ask it to
terminate. @code{dynamic-wind} post thunks will run, but throw handlers terminate, returning the given @var{values}. @code{dynamic-wind} post
will not. If @var{thread} has already terminated or been signaled to thunks will run, but throw handlers will not. If @var{thread} has
terminate, this function is a no-op." already terminated or been signaled to terminate, this function is a
no-op."
(system-async-mark (system-async-mark
(lambda () (lambda ()
(catch #t (catch #t
(lambda () (lambda ()
(abort-to-prompt cancel-tag)) (apply abort-to-prompt cancel-tag values))
(lambda _ (lambda _
(error "thread cancellation failed, throwing error instead???")))) (error "thread cancellation failed, throwing error instead???"))))
thread)) thread))