concurrency.mailboxes: mailboxes should not be disposable, since futures and promises use them in a transient fashion, causing leaks
parent
48fe9029af
commit
7692bd1715
|
@ -42,40 +42,6 @@ IN: concurrency.mailboxes.tests
|
|||
mailbox-get
|
||||
] unit-test
|
||||
|
||||
<mailbox> "m" set
|
||||
|
||||
1 <count-down> "c" set
|
||||
1 <count-down> "d" set
|
||||
|
||||
[
|
||||
"c" get await
|
||||
[ "m" get mailbox-get drop ]
|
||||
[ drop "d" get count-down ] recover
|
||||
] "Mailbox close test" spawn drop
|
||||
|
||||
[ ] [ "c" get count-down ] unit-test
|
||||
[ ] [ "m" get dispose ] unit-test
|
||||
[ ] [ "d" get 5 seconds await-timeout ] unit-test
|
||||
|
||||
[ ] [ "m" get dispose ] unit-test
|
||||
|
||||
<mailbox> "m" set
|
||||
|
||||
1 <count-down> "c" set
|
||||
1 <count-down> "d" set
|
||||
|
||||
[
|
||||
"c" get await
|
||||
"m" get wait-for-close
|
||||
"d" get count-down
|
||||
] "Mailbox close test" spawn drop
|
||||
|
||||
[ ] [ "c" get count-down ] unit-test
|
||||
[ ] [ "m" get dispose ] unit-test
|
||||
[ ] [ "d" get 5 seconds await-timeout ] unit-test
|
||||
|
||||
[ ] [ "m" get dispose ] unit-test
|
||||
|
||||
[ { "foo" "bar" } ] [
|
||||
<mailbox>
|
||||
"foo" over mailbox-put
|
||||
|
@ -86,4 +52,3 @@ IN: concurrency.mailboxes.tests
|
|||
[
|
||||
<mailbox> 1 seconds mailbox-get-timeout
|
||||
] [ wait-timeout? ] must-fail-with
|
||||
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
! Copyright (C) 2005, 2008 Chris Double, Slava Pestov.
|
||||
! Copyright (C) 2005, 2010 Chris Double, Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: dlists deques threads sequences continuations
|
||||
destructors namespaces math quotations words kernel
|
||||
arrays assocs init system concurrency.conditions accessors
|
||||
debugger debugger.threads locals fry ;
|
||||
USING: dlists deques threads sequences continuations namespaces
|
||||
math quotations words kernel arrays assocs init system
|
||||
concurrency.conditions accessors debugger debugger.threads
|
||||
locals fry ;
|
||||
IN: concurrency.mailboxes
|
||||
|
||||
TUPLE: mailbox < disposable threads data ;
|
||||
|
||||
M: mailbox dispose* threads>> notify-all ;
|
||||
TUPLE: mailbox threads data ;
|
||||
|
||||
: <mailbox> ( -- mailbox )
|
||||
mailbox new-disposable <dlist> >>threads <dlist> >>data ;
|
||||
mailbox new
|
||||
<dlist> >>threads
|
||||
<dlist> >>data ;
|
||||
|
||||
: mailbox-empty? ( mailbox -- bool )
|
||||
data>> deque-empty? ;
|
||||
|
@ -24,14 +24,12 @@ M: mailbox dispose* threads>> notify-all ;
|
|||
[ threads>> ] dip "mailbox" wait ;
|
||||
|
||||
:: block-unless-pred ( mailbox timeout pred: ( message -- ? ) -- )
|
||||
mailbox check-disposed
|
||||
mailbox data>> pred dlist-any? [
|
||||
mailbox timeout wait-for-mailbox
|
||||
mailbox timeout pred block-unless-pred
|
||||
] unless ; inline recursive
|
||||
|
||||
: block-if-empty ( mailbox timeout -- mailbox )
|
||||
over check-disposed
|
||||
over mailbox-empty? [
|
||||
2dup wait-for-mailbox block-if-empty
|
||||
] [
|
||||
|
|
Loading…
Reference in New Issue