refine failure handling of thread-send
svn: r9012
This commit is contained in:
parent
a0cbc54b87
commit
2834b00b7e
|
@ -232,10 +232,16 @@ asynchronous channel.
|
||||||
|
|
||||||
@margin-note/ref{See also @secref["async-channel"].}
|
@margin-note/ref{See also @secref["async-channel"].}
|
||||||
|
|
||||||
@defproc[(thread-send [thd thread?] [v any/c]) void?]{
|
@defproc[(thread-send [thd thread?] [v any/c]
|
||||||
|
[fail-thunk (-> any)
|
||||||
|
(lambda () (raise-mismatch-error ....))])
|
||||||
|
any]{
|
||||||
|
|
||||||
Queues @scheme[v] as a message to @scheme[thd]. This function never
|
Queues @scheme[v] as a message to @scheme[thd] without blocking. If
|
||||||
blocks.}
|
the message is queued, the result is @|void-const|. If @scheme[thd] is
|
||||||
|
stops running---as in @scheme[thread-running?]---before the message is
|
||||||
|
queued, then @scheme[fail-thunk] is called (through a tail call) to
|
||||||
|
produce the result.}
|
||||||
|
|
||||||
@defproc[(thread-receive) any/c]{
|
@defproc[(thread-receive) any/c]{
|
||||||
|
|
||||||
|
|
|
@ -724,6 +724,12 @@
|
||||||
(thread-send t 2)
|
(thread-send t 2)
|
||||||
(sync (system-idle-evt))
|
(sync (system-idle-evt))
|
||||||
(test '(0 1 2) values s))
|
(test '(0 1 2) values s))
|
||||||
|
(let ([t (thread void)])
|
||||||
|
(sync (system-idle-evt))
|
||||||
|
(test 'z thread-send t 'x (lambda () 'z))
|
||||||
|
(test-values '(a z) (lambda ()
|
||||||
|
(thread-send t 'x (lambda () (values 'a 'z)))))
|
||||||
|
(err/rt-test (thread-send t 'x)))
|
||||||
|
|
||||||
;; ----------------------------------------
|
;; ----------------------------------------
|
||||||
;; Garbage collection
|
;; Garbage collection
|
||||||
|
|
|
@ -146,7 +146,7 @@ void scheme_init_sema(Scheme_Env *env)
|
||||||
scheme_add_global_constant("thread-send",
|
scheme_add_global_constant("thread-send",
|
||||||
scheme_make_prim_w_arity(thread_send,
|
scheme_make_prim_w_arity(thread_send,
|
||||||
"thread-send",
|
"thread-send",
|
||||||
2, 2),
|
2, 3),
|
||||||
env);
|
env);
|
||||||
scheme_add_global_constant("thread-receive",
|
scheme_add_global_constant("thread-receive",
|
||||||
scheme_make_prim_w_arity(thread_receive,
|
scheme_make_prim_w_arity(thread_receive,
|
||||||
|
@ -1076,7 +1076,7 @@ static Scheme_Object *thread_send(int argc, Scheme_Object **argv)
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
return _scheme_tail_apply(argv[2], 0, NULL);
|
return _scheme_tail_apply(argv[2], 0, NULL);
|
||||||
} else
|
} else
|
||||||
scheme_raise_exn(MZEXN_FAIL, "thread-send: thread is not running");
|
scheme_raise_exn(MZEXN_FAIL_CONTRACT, "thread-send: target thread is not running");
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
scheme_wrong_type("thread-send", "thread", 0, argc, argv);
|
scheme_wrong_type("thread-send", "thread", 0, argc, argv);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user