refine failure handling of thread-send

svn: r9012
This commit is contained in:
Matthew Flatt 2008-03-18 02:16:06 +00:00
parent a0cbc54b87
commit 2834b00b7e
3 changed files with 17 additions and 5 deletions

View File

@ -232,10 +232,16 @@ asynchronous 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
blocks.}
Queues @scheme[v] as a message to @scheme[thd] without blocking. If
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]{

View File

@ -724,6 +724,12 @@
(thread-send t 2)
(sync (system-idle-evt))
(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

View File

@ -146,7 +146,7 @@ void scheme_init_sema(Scheme_Env *env)
scheme_add_global_constant("thread-send",
scheme_make_prim_w_arity(thread_send,
"thread-send",
2, 2),
2, 3),
env);
scheme_add_global_constant("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) {
return _scheme_tail_apply(argv[2], 0, NULL);
} 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
scheme_wrong_type("thread-send", "thread", 0, argc, argv);