TUPLE: linked-thread < thread supervisor ;
M: linked-thread error-in-thread
- [ <linked-error> ] [ supervisor>> ] bi mailbox-put ;
+ [ <linked-error> ] [ supervisor>> ] bi mailbox-put stop ;
: <linked-thread> ( quot name mailbox -- thread' )
[ linked-thread new-thread ] dip >>supervisor ;
! Copyright (C) 2008, 2011 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien debugger continuations threads
-threads.private io io.styles prettyprint kernel make math.parser
-namespaces ;
+USING: accessors debugger continuations threads io io.styles
+prettyprint kernel make math.parser namespaces ;
IN: debugger.threads
: error-in-thread. ( thread -- )
", " % dup quot>> unparse-short % ")" %
] "" make swap write-object ":" print ;
-: call-thread-error-handler? ( thread -- ? )
- initial-thread get-global eq?
- in-callback?
- or not ;
-
-M: thread error-in-thread ( error thread -- )
- global [
- error-in-thread. nl
- print-error nl
- :c
- flush
- ] bind ;
-
+! ( error thread -- )
[
- dup call-thread-error-handler?
- [ self error-in-thread stop ]
- [ [ die ] call( error thread -- * ) ] if
+ dup initial-thread get-global eq? [ die ] [
+ global [
+ error-in-thread. nl
+ print-error nl
+ :c
+ flush
+ ] bind
+ stop
+ ] if
] thread-error-hook set-global
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2011 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: init io.backend kernel namespaces threads ;
+USING: continuations init io.backend kernel namespaces threads ;
IN: io.thread
! The Cocoa and Gtk UI backend stops the I/O thread and takes
"I/O wait"
io-thread new-thread ;
-M: io-thread error-in-thread [ die ] call( error thread -- ) ;
+M: io-thread error-in-thread [ die ] call( error thread -- * ) ;
: start-io-thread ( -- )
t io-thread-running? set-global
'[ _ set-datastack @ ]
"Thread" spawn drop ;
-GENERIC: error-in-thread ( error thread -- )
-
<PRIVATE
: init-thread-state ( -- )
] when
strip-debugger? [
- {
- compiler.errors:compiler-errors
- continuations:thread-error-hook
- } %
+ \ compiler.errors:compiler-errors ,
] when
"windows-messages" "windows.messages" lookup [ , ] when*
--- /dev/null
+! Copyright (C) 2011 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors continuations concurrency.mailboxes
+concurrency.messaging kernel system threads ;
+IN: tools.deploy.test.22
+
+: linked-error-test ( -- )
+ [ "Linked" throw ] "Test" spawn-linked drop
+ [ receive drop 1 ] [ error>> "Linked" = 0 1 ? ] recover
+ exit ;
+
+MAIN: linked-error-test
--- /dev/null
+USING: tools.deploy.config ;
+H{
+ { deploy-c-types? f }
+ { deploy-help? f }
+ { deploy-name "tools.deploy.test.22" }
+ { "stop-after-last-window?" t }
+ { deploy-unicode? f }
+ { deploy-console? t }
+ { deploy-io 2 }
+ { deploy-reflection 1 }
+ { deploy-ui? f }
+ { deploy-word-defs? f }
+ { deploy-threads? t }
+ { deploy-math? t }
+ { deploy-word-props? f }
+}
PRIVATE>
-: in-callback? ( -- ? ) 3 context-object ;
-
: initialize-alien ( symbol quot -- )
swap dup get-global dup recompute-value?
[ drop [ call dup 31337 <alien> expiry-check boa ] dip set-global ]
{ $var-description "Global variable holding the set of possible restarts for the most recently thrown error." }
{ $notes "Only updated by " { $link throw } ", not " { $link rethrow } "." } ;
-HELP: >c
-{ $values { "continuation" continuation } }
-{ $description "Pushes an exception handler continuation on the catch stack. The continuation must have been reified by " { $link callcc1 } "." } ;
-
-HELP: c>
-{ $values { "continuation" continuation } }
-{ $description "Pops an exception handler continuation from the catch stack." } ;
-
HELP: throw
{ $values { "error" object } }
{ $description "Saves the current continuation in the " { $link error-continuation } " global variable and throws an error. Execution does not continue at the point after the " { $link throw } " call. Rather, the innermost catch block is invoked, and execution continues at that point." } ;
-! Copyright (C) 2003, 2010 Slava Pestov.
+! Copyright (C) 2003, 2011 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays vectors kernel kernel.private sequences
namespaces make math splitting sorting quotations assocs
: catchstack* ( -- catchstack )
1 context-object { vector } declare ; inline
-: >c ( continuation -- ) catchstack* push ;
-
-: c> ( -- continuation ) catchstack* pop ;
-
! We have to defeat some optimizations to make continuations work
: dummy-1 ( -- obj ) f ;
-: dummy-2 ( obj -- obj ) dup drop ;
+: dummy-2 ( obj -- obj ) ;
: catchstack ( -- catchstack ) catchstack* clone ; inline
PRIVATE>
-SYMBOL: thread-error-hook
+GENERIC: error-in-thread ( error thread -- * )
+
+SYMBOL: thread-error-hook ! ( error thread -- )
+
+thread-error-hook [ [ die ] ] initialize
+
+M: object error-in-thread ( error thread -- )
+ thread-error-hook get-global call( error thread -- * ) ;
+
+: in-callback? ( -- ? ) 3 context-object ;
+
+SYMBOL: callback-error-hook ! ( error -- * )
+
+callback-error-hook [ [ die ] ] initialize
: rethrow ( error -- * )
dup save-error
- catchstack* empty? [
- thread-error-hook get-global
- [ original-error get-global die ] or
- (( error -- * )) call-effect-unsafe
- ] when
- c> continue-with ;
+ catchstack* [
+ in-callback?
+ [ callback-error-hook get-global call( error -- * ) ]
+ [ 63 special-object error-in-thread ]
+ if
+ ] [ pop continue-with ] if-empty ;
: recover ( ..a try: ( ..a -- ..b ) recovery: ( ..a error -- ..b ) -- ..b )
- [ [ swap >c call c> drop ] curry ] dip ifcc ; inline
+ [
+ [
+ [ catchstack* push ] dip
+ call
+ catchstack* pop*
+ ] curry
+ ] dip ifcc ; inline
: ignore-errors ( quot -- )
[ drop ] recover ; inline