1 USING: io memory namespaces tools.test threads threads.private kernel
2 concurrency.combinators concurrency.promises locals math
3 words calendar sequences fry ;
7 ! The start-context-and-delete primitive calls reset_context which
8 ! causes reads to uninitialized locations in the data segment if it
13 ! This word attempts to fill the nursery so that there is less than 48
14 ! bytes of free space in it. The constant used to fill is volatile but
15 ! should work on 64 bit.
16 : fill-nursery ( -- obj )
17 minor-gc 48074 [ tup1 new ] replicate ;
19 : do-reset-context ( -- val )
20 ! "main running" print flush
21 [ "a" print ] "foo1" spawn drop
22 [ "b" print ] "foo2" spawn drop
29 do-reset-context length
33 [ 2 "x" set ] "Test" spawn drop
34 { 2 } [ yield "x" get ] unit-test
35 { } [ [ flush ] "flush test" spawn drop flush ] unit-test
36 { } [ [ "Errors, errors" throw ] "error test" spawn drop ] unit-test
39 { } [ 0.3 sleep ] unit-test
40 [ "hey" sleep ] must-fail
42 { 3 } [ 3 self resume-with "Test suspend" suspend ] unit-test
44 { f } [ f get-global ] unit-test
46 { { 0 3 6 9 12 15 18 21 24 27 } } [
50 "i" [ yield 3 + ] tchange
56 :: spawn-namespace-test ( -- ? )
57 <promise> :> p gensym :> g
59 [ "x" get p fulfill ] "B" spawn drop
63 { t } [ spawn-namespace-test ] unit-test
65 [ "a" [ 1 1 + ] spawn 100 sleep ] must-fail
67 { } [ 0.1 seconds sleep ] unit-test
69 ! Test thread-local variables
74 { 5 } [ "x" tget ] unit-test
76 { } [ "x" [ 1 + ] tchange ] unit-test
78 { 6 } [ "x" tget ] unit-test
80 ! Are they truly thread-local?
81 [ "x" tget "p" get fulfill ] in-thread
83 { f } [ "p" get ?promise ] unit-test
85 ! Test system traps inside threads
86 { } [ [ dup ] in-thread yield ] unit-test
88 ! The start-context-and-delete primitive wasn't rewinding the
91 ! This got fixed for x86-64 but the problem remained on x86-32.
93 ! The unit test asserts that the callstack is empty from the
94 ! quotation passed to start-context-and-delete.
100 [ callstack swap fulfill stop ] start-context-and-delete
101 ] start-context-and-delete
103 ] [ ?promise callstack>array length ] bi