From 9edb5875e3ffc62013f48d61dfc8aea1fbdb9b3b Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 18 Feb 2008 07:30:16 -0600 Subject: [PATCH] Less drastic changes --- core/alien/compiler/compiler.factor | 4 +- .../remote-control/remote-control.factor | 4 +- core/compiler/compiler.factor | 4 +- core/generator/generator.factor | 2 +- core/io/thread/thread.factor | 8 +- core/{concurrency => }/threads/authors.txt | 0 core/{concurrency => }/threads/summary.txt | 0 .../threads/threads-docs.factor | 8 +- .../threads/threads-tests.factor | 2 +- core/{concurrency => }/threads/threads.factor | 16 ++- extra/alarms/alarms.factor | 10 +- extra/benchmark/ring/ring.factor | 6 +- extra/benchmark/sockets/sockets.factor | 4 +- extra/calendar/model/model.factor | 2 +- extra/channels/channels-tests.factor | 0 extra/channels/channels.factor | 0 extra/channels/examples/examples.factor | 10 +- extra/channels/remote/remote.factor | 9 +- extra/channels/sniffer/bsd/bsd.factor | 11 +- extra/cocoa/application/application.factor | 4 +- .../distributed/distributed-docs.factor | 16 +-- .../distributed/distributed.factor | 2 +- .../concurrency/exchangers/exchangers.factor | 2 +- extra/concurrency/locks/locks.factor | 2 +- .../messaging/messaging-docs.factor | 109 ++++++------------ .../messaging/messaging-tests.factor | 2 +- extra/concurrency/messaging/messaging.factor | 23 ++-- extra/crypto/random.factor | 2 +- extra/io/launcher/launcher.factor | 2 +- extra/io/monitors/monitors.factor | 2 +- extra/io/server/server.factor | 10 +- extra/io/sockets/sockets-docs.factor | 2 +- extra/io/timeouts/timeouts.factor | 2 +- extra/io/unix/backend/backend.factor | 7 +- extra/io/unix/bsd/bsd.factor | 4 +- extra/io/unix/kqueue/kqueue.factor | 3 +- extra/io/unix/launcher/launcher.factor | 6 +- extra/io/unix/linux/linux.factor | 4 +- extra/io/unix/sockets/sockets.factor | 10 +- extra/io/unix/unix-tests.factor | 6 +- extra/io/windows/launcher/launcher.factor | 7 +- extra/io/windows/nt/backend/backend.factor | 2 +- extra/io/windows/nt/files/files.factor | 2 +- extra/io/windows/nt/sockets/sockets.factor | 2 +- extra/logging/logging.factor | 2 +- extra/logging/server/server.factor | 21 ++-- extra/pack/pack.factor | 2 +- extra/space-invaders/space-invaders.factor | 9 +- extra/tools/interpreter/interpreter.factor | 2 +- extra/tools/threads/threads.factor | 2 +- extra/ui/tools/interactor/interactor.factor | 12 +- extra/ui/tools/listener/listener.factor | 2 +- extra/ui/tools/walker/walker.factor | 2 +- extra/ui/ui.factor | 2 +- extra/ui/windows/windows.factor | 2 +- extra/vocabs/monitor/monitor.factor | 16 ++- extra/webapps/planet/planet.factor | 8 +- 57 files changed, 192 insertions(+), 223 deletions(-) rename core/{concurrency => }/threads/authors.txt (100%) rename core/{concurrency => }/threads/summary.txt (100%) rename core/{concurrency => }/threads/threads-docs.factor (97%) rename core/{concurrency => }/threads/threads-tests.factor (85%) rename core/{concurrency => }/threads/threads.factor (93%) mode change 100644 => 100755 extra/alarms/alarms.factor mode change 100644 => 100755 extra/benchmark/ring/ring.factor mode change 100644 => 100755 extra/channels/channels-tests.factor mode change 100644 => 100755 extra/channels/channels.factor mode change 100644 => 100755 extra/channels/remote/remote.factor mode change 100644 => 100755 extra/channels/sniffer/bsd/bsd.factor mode change 100644 => 100755 extra/cocoa/application/application.factor mode change 100644 => 100755 extra/concurrency/distributed/distributed-docs.factor mode change 100644 => 100755 extra/concurrency/messaging/messaging-docs.factor mode change 100644 => 100755 extra/crypto/random.factor mode change 100644 => 100755 extra/pack/pack.factor diff --git a/core/alien/compiler/compiler.factor b/core/alien/compiler/compiler.factor index 24408e1e20..48e8d7e307 100755 --- a/core/alien/compiler/compiler.factor +++ b/core/alien/compiler/compiler.factor @@ -5,8 +5,8 @@ hashtables kernel math namespaces sequences words inference.state inference.backend inference.dataflow system math.parser classes alien.arrays alien.c-types alien.structs alien.syntax cpu.architecture alien inspector quotations assocs -kernel.private concurrency.threads continuations.private libc -combinators compiler.errors continuations ; +kernel.private threads continuations.private libc combinators +compiler.errors continuations ; IN: alien.compiler ! Common protocol for alien-invoke/alien-callback/alien-indirect diff --git a/core/alien/remote-control/remote-control.factor b/core/alien/remote-control/remote-control.factor index f3c84119bf..b7700c0ff1 100755 --- a/core/alien/remote-control/remote-control.factor +++ b/core/alien/remote-control/remote-control.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2007 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: alien alien.c-types parser concurrency.threads words -kernel.private kernel ; +USING: alien alien.c-types parser threads words kernel.private +kernel ; IN: alien.remote-control : eval-callback diff --git a/core/compiler/compiler.factor b/core/compiler/compiler.factor index 3f06f85d10..f0caec7ad1 100755 --- a/core/compiler/compiler.factor +++ b/core/compiler/compiler.factor @@ -3,8 +3,8 @@ USING: kernel namespaces arrays sequences io inference.backend inference.state generator debugger math.parser prettyprint words compiler.units continuations vocabs assocs alien.compiler dlists -optimizer definitions math compiler.errors concurrency.threads -graphs generic ; +optimizer definitions math compiler.errors threads graphs +generic ; IN: compiler : compiled-usages ( words -- seq ) diff --git a/core/generator/generator.factor b/core/generator/generator.factor index c62fc9f8a2..3514947e3d 100755 --- a/core/generator/generator.factor +++ b/core/generator/generator.factor @@ -5,7 +5,7 @@ effects generator.fixup generator.registers generic hashtables inference inference.backend inference.dataflow io kernel kernel.private layouts math namespaces optimizer optimizer.specializers prettyprint quotations sequences system -concurrency.threads words vectors ; +threads words vectors ; IN: generator SYMBOL: compile-queue diff --git a/core/io/thread/thread.factor b/core/io/thread/thread.factor index ec118dcbf7..53ab5193c6 100755 --- a/core/io/thread/thread.factor +++ b/core/io/thread/thread.factor @@ -1,14 +1,14 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. IN: io.thread -USING: concurrency.threads io.backend namespaces init ; +USING: threads io.backend namespaces init ; : io-thread ( -- ) - sleep-time io-multiplex yield io-thread ; + sleep-time io-multiplex yield ; : start-io-thread ( -- ) - [ io-thread ] - "I/O wait" spawn + [ io-thread t ] + "I/O wait" spawn-server \ io-thread set-global ; [ start-io-thread ] "io.thread" add-init-hook diff --git a/core/concurrency/threads/authors.txt b/core/threads/authors.txt similarity index 100% rename from core/concurrency/threads/authors.txt rename to core/threads/authors.txt diff --git a/core/concurrency/threads/summary.txt b/core/threads/summary.txt similarity index 100% rename from core/concurrency/threads/summary.txt rename to core/threads/summary.txt diff --git a/core/concurrency/threads/threads-docs.factor b/core/threads/threads-docs.factor similarity index 97% rename from core/concurrency/threads/threads-docs.factor rename to core/threads/threads-docs.factor index 53acb40794..0a9e1b0bac 100755 --- a/core/concurrency/threads/threads-docs.factor +++ b/core/threads/threads-docs.factor @@ -1,7 +1,7 @@ USING: help.markup help.syntax kernel kernel.private io -concurrency.threads.private continuations dlists init -quotations strings assocs heaps ; -IN: concurrency.threads +threads.private continuations dlists init quotations strings +assocs heaps ; +IN: threads ARTICLE: "threads-start/stop" "Starting and stopping threads" "Spawning new threads:" @@ -44,7 +44,7 @@ ARTICLE: "thread-impl" "Thread implementation" ARTICLE: "threads" "Lightweight co-operative threads" "Factor supports lightweight co-operative threads implemented on top of continuations. A thread will yield while waiting for I/O operations to complete, or when a yield has been explicitly requested." $nl -"Words for working with threads are in the " { $vocab-link "concurrency.threads" } " vocabulary." +"Words for working with threads are in the " { $vocab-link "threads" } " vocabulary." { $subsection "threads-start/stop" } { $subsection "threads-yield" } { $subsection "thread-state" } diff --git a/core/concurrency/threads/threads-tests.factor b/core/threads/threads-tests.factor similarity index 85% rename from core/concurrency/threads/threads-tests.factor rename to core/threads/threads-tests.factor index 2bd7e8aa4c..49139a7807 100755 --- a/core/concurrency/threads/threads-tests.factor +++ b/core/threads/threads-tests.factor @@ -1,4 +1,4 @@ -USING: namespaces io tools.test concurrency.threads kernel ; +USING: namespaces io tools.test threads kernel ; IN: temporary 3 "x" set diff --git a/core/concurrency/threads/threads.factor b/core/threads/threads.factor similarity index 93% rename from core/concurrency/threads/threads.factor rename to core/threads/threads.factor index 1a11a00b82..04487e16b4 100755 --- a/core/concurrency/threads/threads.factor +++ b/core/threads/threads.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2004, 2008 Slava Pestov. ! Copyright (C) 2005 Mackenzie Straight. ! See http://factorcode.org/license.txt for BSD license. -IN: concurrency.threads +IN: threads USING: arrays hashtables heaps kernel kernel.private math namespaces sequences vectors continuations continuations.private dlists assocs system combinators debugger prettyprint io init ; @@ -53,6 +53,8 @@ threads global [ H{ } assoc-like ] change-at : set-self ( thread -- ) 40 setenv ; inline +PRIVATE> + : ( quot name error-handler -- thread ) \ thread counter H{ } clone { set-thread-quot @@ -62,8 +64,6 @@ threads global [ H{ } assoc-like ] change-at set-thread-variables } \ thread construct ; -PRIVATE> - SYMBOL: run-queue SYMBOL: sleep-queue @@ -149,7 +149,13 @@ PRIVATE> ] [ (spawn) ] keep ; -: in-thread ( quot -- ) "Thread" spawn drop ; +: spawn-server ( quot name -- thread ) + >r [ [ ] [ ] while ] curry r> spawn ; + +: in-thread ( quot -- ) + >r datastack namestack r> + [ >r set-namestack set-datastack r> call ] 3curry + "Thread" spawn drop ; -[ init-threads ] "concurrency.threads" add-init-hook +[ init-threads ] "threads" add-init-hook diff --git a/extra/alarms/alarms.factor b/extra/alarms/alarms.factor old mode 100644 new mode 100755 index 4540b7b2aa..40eda02fac --- a/extra/alarms/alarms.factor +++ b/extra/alarms/alarms.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2007 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: arrays calendar combinators concurrency generic -init kernel math namespaces sequences threads ; +USING: arrays calendar combinators concurrency.messaging +threads generic init kernel math namespaces sequences ; IN: alarms TUPLE: alarm time quot ; @@ -36,7 +36,7 @@ SYMBOL: alarm-looper [ alarm-time <=> 0 <= ] with subset ; : call-alarm ( alarm -- ) - alarm-quot spawn drop ; + alarm-quot "Alarm invocation" spawn drop ; : do-alarms ( -- ) expired-alarms [ call-alarm ] each @@ -49,7 +49,7 @@ SYMBOL: alarm-looper : start-alarm-receiver ( -- ) [ alarm-receive-loop - ] spawn alarm-receiver set-global ; + ] "Alarm receiver" spawn alarm-receiver set-global ; : alarm-loop ( -- ) alarms get-global empty? [ @@ -59,7 +59,7 @@ SYMBOL: alarm-looper : start-alarm-looper ( -- ) [ alarm-loop - ] spawn alarm-looper set-global ; + ] "Alarm looper" spawn alarm-looper set-global ; : send-alarm ( str alarm -- ) over set-delegate diff --git a/extra/benchmark/ring/ring.factor b/extra/benchmark/ring/ring.factor old mode 100644 new mode 100755 index b0d02c4239..f1b7d6c9cc --- a/extra/benchmark/ring/ring.factor +++ b/extra/benchmark/ring/ring.factor @@ -1,4 +1,5 @@ -USING: concurrency kernel tools.time math sequences ; +USING: threads concurrency.messaging kernel +tools.time math sequences ; IN: benchmark.ring SYMBOL: done @@ -7,7 +8,7 @@ SYMBOL: done receive 2dup swap send done eq? [ tunnel ] unless ; : create-ring ( processes -- target ) - self swap [ [ tunnel ] spawn nip ] times ; + self swap [ [ tunnel ] "Tunnel" spawn nip ] times ; : send-messages ( messages target -- ) dupd [ send ] curry each [ receive drop ] times ; @@ -22,4 +23,3 @@ SYMBOL: done 1000 1000 ring-bench ; MAIN: main-ring-bench - diff --git a/extra/benchmark/sockets/sockets.factor b/extra/benchmark/sockets/sockets.factor index a621331968..40012e1638 100755 --- a/extra/benchmark/sockets/sockets.factor +++ b/extra/benchmark/sockets/sockets.factor @@ -1,5 +1,5 @@ -USING: io.sockets io.server io kernel math threads debugger -concurrency tools.time prettyprint ; +USING: io.sockets io.server io kernel math threads +debugger tools.time prettyprint ; IN: benchmark.sockets : simple-server ( -- ) diff --git a/extra/calendar/model/model.factor b/extra/calendar/model/model.factor index 61ab191b75..be98c7491e 100755 --- a/extra/calendar/model/model.factor +++ b/extra/calendar/model/model.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2008 Slava Pestov ! See http://factorcode.org/license.txt for BSD license. -USING: calendar namespaces models concurrency.threads init ; +USING: calendar namespaces models threads init ; IN: calendar.model SYMBOL: time diff --git a/extra/channels/channels-tests.factor b/extra/channels/channels-tests.factor old mode 100644 new mode 100755 diff --git a/extra/channels/channels.factor b/extra/channels/channels.factor old mode 100644 new mode 100755 diff --git a/extra/channels/examples/examples.factor b/extra/channels/examples/examples.factor index 87b755614a..dda2a4921b 100755 --- a/extra/channels/examples/examples.factor +++ b/extra/channels/examples/examples.factor @@ -2,8 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. ! ! Examples of using channels -USING: kernel concurrency channels math namespaces locals -sequences ; +USING: kernel threads channels math namespaces +locals sequences ; IN: channels.examples : (counter) ( channel n -- ) @@ -13,7 +13,7 @@ IN: channels.examples 2 (counter) ; : counter-test ( -- n1 n2 n3 ) - [ counter ] spawn drop + dup [ counter ] curry "Counter" spawn drop [ from ] keep [ from ] keep from ; : filter ( send prime recv -- ) @@ -34,11 +34,11 @@ IN: channels.examples : sieve ( prime -- ) #! Send prime numbers to 'prime' channel - [ counter ] spawn drop + dup [ counter ] curry "Counter" spawn drop (sieve) ; : sieve-test ( -- seq ) - [ sieve ] spawn drop + dup [ sieve ] curry "Sieve" spawn drop V{ } clone swap [ from swap push ] 2keep [ from swap push ] 2keep diff --git a/extra/channels/remote/remote.factor b/extra/channels/remote/remote.factor old mode 100644 new mode 100755 index 4f483b8775..40a6df350b --- a/extra/channels/remote/remote.factor +++ b/extra/channels/remote/remote.factor @@ -3,7 +3,8 @@ ! ! Remote Channels USING: kernel init namespaces assocs arrays random -sequences channels match concurrency concurrency.distributed ; +sequences channels match concurrency.messaging +concurrency.distributed ; IN: channels.remote : start-channel-node ( -- ) - "remote-channels" get-process [ - [ channel-process ] spawn "remote-channels" swap register-process + "remote-channels" get-process [ + "remote-channels" + [ channel-process ] "Remote channels" spawn + register-process ] unless ; TUPLE: remote-channel node id ; diff --git a/extra/channels/sniffer/bsd/bsd.factor b/extra/channels/sniffer/bsd/bsd.factor old mode 100644 new mode 100755 index 0ba267bb03..f986f11484 --- a/extra/channels/sniffer/bsd/bsd.factor +++ b/extra/channels/sniffer/bsd/bsd.factor @@ -2,12 +2,15 @@ ! See http://factorcode.org/license.txt for BSD license. ! ! Wrap a sniffer in a channel -USING: kernel channels channels.sniffer.backend concurrency io -io.sniffer.backend io.sniffer.bsd io.unix.backend ; +USING: kernel channels channels.sniffer.backend +threads io io.sniffer.backend io.sniffer.bsd +io.unix.backend ; IN: channels.sniffer.bsd M: unix-io sniff-channel ( -- channel ) "/dev/bpf0" "en1" [ - (sniff-channel) - ] spawn drop nip ; + [ + (sniff-channel) + ] 3curry spawn drop + ] keep ; diff --git a/extra/cocoa/application/application.factor b/extra/cocoa/application/application.factor old mode 100644 new mode 100755 index 709d318e63..0cf020a087 --- a/extra/cocoa/application/application.factor +++ b/extra/cocoa/application/application.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2006, 2007 Slava Pestov ! See http://factorcode.org/license.txt for BSD license. USING: alien io kernel namespaces core-foundation cocoa.messages -cocoa cocoa.classes cocoa.runtime sequences threads debugger -init inspector kernel.private ; +cocoa cocoa.classes cocoa.runtime sequences threads +debugger init inspector kernel.private ; IN: cocoa.application : ( str -- alien ) -> autorelease ; diff --git a/extra/concurrency/distributed/distributed-docs.factor b/extra/concurrency/distributed/distributed-docs.factor old mode 100644 new mode 100755 index 23af641600..8f82d1aebf --- a/extra/concurrency/distributed/distributed-docs.factor +++ b/extra/concurrency/distributed/distributed-docs.factor @@ -1,4 +1,4 @@ -USING: help.markup help.syntax concurrency ; +USING: help.markup help.syntax concurrency.messaging ; IN: concurrency.distributed HELP: @@ -7,19 +7,9 @@ HELP: { "remote-process" "the constructed remote-process object" } } { $description "Constructs a proxy to a process running on another node. It can be used to send messages to the process it is acting as a proxy for." } -{ $see-also spawn send } ; - - -HELP: -{ $values { "hostname" "the hostname of the node as a string" } - { "port" "the integer port number of the node" } - { "node" "the constructed node object" } -} -{ $description "Processes run on nodes. Each node has a hostname and a port." } -{ $see-also localnode } ; +{ $see-also spawn send } ; HELP: localnode { $values { "node" "a node object" } } -{ $description "Return the node the process is currently running on." } -{ $see-also } ; +{ $description "Return the node the process is currently running on." } ; diff --git a/extra/concurrency/distributed/distributed.factor b/extra/concurrency/distributed/distributed.factor index 042c33306e..30587b35ac 100755 --- a/extra/concurrency/distributed/distributed.factor +++ b/extra/concurrency/distributed/distributed.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2005 Chris Double. All Rights Reserved. ! See http://factorcode.org/license.txt for BSD license. USING: serialize sequences concurrency.messaging -concurrency.threads io io.server qualified arrays +threads io io.server qualified arrays namespaces kernel ; QUALIFIED: io.sockets IN: concurrency.distributed diff --git a/extra/concurrency/exchangers/exchangers.factor b/extra/concurrency/exchangers/exchangers.factor index 39f01ae2ca..e2c701c7a9 100755 --- a/extra/concurrency/exchangers/exchangers.factor +++ b/extra/concurrency/exchangers/exchangers.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel concurrency.threads ; +USING: kernel threads ; IN: concurrency.exchangers ! Motivated by diff --git a/extra/concurrency/locks/locks.factor b/extra/concurrency/locks/locks.factor index 182bf0a106..3a792768a7 100755 --- a/extra/concurrency/locks/locks.factor +++ b/extra/concurrency/locks/locks.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: dlists kernel concurrency.threads continuations math ; +USING: dlists kernel threads continuations math ; IN: concurrency.locks ! Simple critical sections diff --git a/extra/concurrency/messaging/messaging-docs.factor b/extra/concurrency/messaging/messaging-docs.factor old mode 100644 new mode 100755 index 16a2e65a90..a22014a106 --- a/extra/concurrency/messaging/messaging-docs.factor +++ b/extra/concurrency/messaging/messaging-docs.factor @@ -1,93 +1,80 @@ ! Copyright (C) 2006 Chris Double. ! See http://factorcode.org/license.txt for BSD license. -USING: help.syntax help.markup concurrency.private match ; -IN: concurrency +USING: help.syntax help.markup concurrency.messaging.private +threads ; +IN: concurrency.messaging -HELP: make-mailbox -{ $values { "mailbox" "a mailbox object" } +HELP: +{ $values { "mailbox" mailbox } } { $description "A mailbox is an object that can be used for safe thread communication. Items can be put in the mailbox and retrieved in a FIFO order. If the mailbox is empty when a get operation is performed then the thread will block until another thread places something in the mailbox. If multiple threads are waiting on the same mailbox, only one of the waiting threads will be unblocked to process the get operation." } { $see-also mailbox-empty? mailbox-put mailbox-get mailbox-get-all while-mailbox-empty mailbox-get? } ; HELP: mailbox-empty? -{ $values { "mailbox" "a mailbox object" } - { "bool" "a boolean value" } +{ $values { "mailbox" mailbox } + { "bool" "a boolean" } } { $description "Return true if the mailbox is empty." } -{ $see-also make-mailbox mailbox-put mailbox-get mailbox-get-all while-mailbox-empty mailbox-get? } ; +{ $see-also mailbox-put mailbox-get mailbox-get-all while-mailbox-empty mailbox-get? } ; HELP: mailbox-put { $values { "obj" "an object" } - { "mailbox" "a mailbox object" } + { "mailbox" mailbox } } { $description "Put the object into the mailbox. Any threads that have a blocking get on the mailbox are resumed. Only one of those threads will successfully get the object, the rest will immediately block waiting for the next item in the mailbox." } -{ $see-also make-mailbox mailbox-empty? mailbox-get mailbox-get-all while-mailbox-empty mailbox-get? } ; +{ $see-also mailbox-empty? mailbox-get mailbox-get-all while-mailbox-empty mailbox-get? } ; -HELP: (mailbox-block-unless-pred) +HELP: block-unless-pred { $values { "pred" "a quotation with stack effect " { $snippet "( X -- bool )" } } - { "mailbox" "a mailbox object" } + { "mailbox" mailbox } { "timeout" "a timeout in milliseconds" } } -{ $description "Block the thread if there are no items in the mailbox that return true when the predicate is called with the item on the stack. The predicate must have stack effect " { $snippet "( X -- bool )" } "." } -{ $see-also make-mailbox mailbox-empty? mailbox-put mailbox-get mailbox-get-all while-mailbox-empty mailbox-get? } ; +{ $description "Block the thread if there are no items in the mailbox that return true when the predicate is called with the item on the stack." } +{ $see-also mailbox-empty? mailbox-put mailbox-get mailbox-get-all while-mailbox-empty mailbox-get? } ; -HELP: (mailbox-block-if-empty) -{ $values { "mailbox" "a mailbox object" } +HELP: block-if-empty +{ $values { "mailbox" mailbox } { "mailbox2" "same object as 'mailbox'" } { "timeout" "a timeout in milliseconds" } } { $description "Block the thread if the mailbox is empty." } -{ $see-also make-mailbox mailbox-empty? mailbox-put mailbox-get mailbox-get-all while-mailbox-empty mailbox-get? } ; +{ $see-also mailbox-empty? mailbox-put mailbox-get mailbox-get-all while-mailbox-empty mailbox-get? } ; HELP: mailbox-get -{ $values { "mailbox" "a mailbox object" } +{ $values { "mailbox" mailbox } { "obj" "an object" } } { $description "Get the first item put into the mailbox. If it is empty the thread blocks until an item is put into it. The thread then resumes, leaving the item on the stack." } -{ $see-also make-mailbox mailbox-empty? mailbox-put while-mailbox-empty mailbox-get-all mailbox-get? } ; +{ $see-also mailbox-empty? mailbox-put while-mailbox-empty mailbox-get-all mailbox-get? } ; HELP: mailbox-get-all -{ $values { "mailbox" "a mailbox object" } +{ $values { "mailbox" mailbox } { "array" "an array" } } { $description "Blocks the thread if the mailbox is empty, otherwise removes all objects in the mailbox and returns an array containing the objects." } -{ $see-also make-mailbox mailbox-empty? mailbox-put while-mailbox-empty mailbox-get-all mailbox-get? } ; +{ $see-also mailbox-empty? mailbox-put while-mailbox-empty mailbox-get-all mailbox-get? } ; HELP: while-mailbox-empty -{ $values { "mailbox" "a mailbox object" } +{ $values { "mailbox" mailbox } { "quot" "a quotation with stack effect " { $snippet "( -- )" } } } -{ $description "Repeatedly call the quotation while there are no items in the mailbox. Quotation should have stack effect " { $snippet "( -- )" } "." } -{ $see-also make-mailbox mailbox-empty? mailbox-put mailbox-get mailbox-get-all mailbox-get? } ; +{ $description "Repeatedly call the quotation while there are no items in the mailbox." } +{ $see-also mailbox-empty? mailbox-put mailbox-get mailbox-get-all mailbox-get? } ; HELP: mailbox-get? { $values { "pred" "a quotation with stack effect " { $snippet "( X -- bool )" } } - { "mailbox" "a mailbox object" } + { "mailbox" mailbox } { "obj" "an object" } } -{ $description "Get the first item in the mailbox which satisfies the predicate. 'pred' will be called repeatedly for each item in the mailbox. When 'pred' returns true that item will be returned. If nothing in the mailbox satisfies the predicate then the thread will block until something does. 'pred' must have stack effect " { $snippet "( X -- bool }" } "." } -{ $see-also make-mailbox mailbox-empty? mailbox-put mailbox-get mailbox-get-all while-mailbox-empty } ; - -HELP: -{ $values { "links" "an array of processes" } - { "pid" "the process id" } - { "mailbox" "a mailbox object" } -} -{ $description "Constructs a process object. A process is a lightweight thread with a mailbox that can be used to communicate with other processes. Each process has a unique process id." } -{ $see-also spawn send receive } ; - -HELP: self -{ $values { "process" "a process object" } -} -{ $description "Returns the currently running process object." } -{ $see-also send receive receive-if } ; +{ $description "Get the first item in the mailbox which satisfies the predicate. 'pred' will be called repeatedly for each item in the mailbox. When 'pred' returns true that item will be returned. If nothing in the mailbox satisfies the predicate then the thread will block until something does." } +{ $see-also mailbox-empty? mailbox-put mailbox-get mailbox-get-all while-mailbox-empty } ; HELP: send { $values { "message" "an object" } { "process" "a process object" } } { $description "Send the message to the process by placing it in the processes mailbox. This is an asynchronous operation and will return immediately. The receving process will act on the message the next time it retrieves that item from its mailbox (usually using the " { $link receive } " word. The message can be any Factor object. For destinations that are instances of remote-process the message must be a serializable Factor type." } -{ $see-also receive receive-if } ; +{ $see-also receive receive-if } ; HELP: receive { $values { "message" "an object" } @@ -99,27 +86,16 @@ HELP: receive-if { $values { "pred" "a predicate with stack effect " { $snippet "( X -- bool )" } } { "message" "an object" } } -{ $description "Return the first message from the current processes mailbox that satisfies the predicate. To satisfy the predicate, 'pred' is called with the item on the stack and the predicate should leave a boolean indicating whether it was satisfied or not. The predicate must have stack effect " { $snippet "( X -- bool )" } ". If nothing in the mailbox satisfies the predicate then the process will block until something does." } +{ $description "Return the first message from the current processes mailbox that satisfies the predicate. To satisfy the predicate, 'pred' is called with the item on the stack and the predicate should leave a boolean indicating whether it was satisfied or not. If nothing in the mailbox satisfies the predicate then the process will block until something does." } { $see-also send receive } ; -HELP: spawn -{ $values { "quot" "a predicate with stack effect " { $snippet "( -- )" } } - { "process" "a process object" } -} -{ $description "Start a process which runs the given quotation." } -{ $see-also send receive receive-if self spawn-link } ; - -HELP: spawn-link +HELP: spawn-linked { $values { "quot" "a predicate with stack effect " { $snippet "( -- )" } } { "process" "a process object" } } { $description "Start a process which runs the given quotation. If that quotation throws an error which is not caught then the error will get propagated to the process that spawned it. This can be used to set up 'supervisor' processes that restart child processes that crash due to uncaught errors.\n" } { $see-also spawn } ; -ARTICLE: { "concurrency" "loading" } "Loading" -"The Factor module system can be used to load the Concurrency library:" -{ $code "USING: concurrency ;" } ; - ARTICLE: { "concurrency" "processes" } "Processes" "A process is basically a thread with a message queue. Other processes can place items on this queue by sending the process a message. A process can check its queue for messages, blocking if none are pending, and process them as they are queued.\n\nFactor processes are very lightweight. Each process can take as little as 900 bytes of memory. This library has been tested running hundreds of thousands of simple processes.\n\nThe messages that are sent from process to process are any Factor value. Factor tuples are ideal for this sort of thing as you can send a tuple to a process and the predicate dispatch mechanism can be used to perform actions depending on what the type of the tuple is.\n\nProcesses are usually created using " { $link spawn } ". This word takes a quotation on the stack and starts a process that will execute that quotation asynchronously. When the quotation completes the process will die. 'spawn' leaves on the stack the process object that was started. This object can be used to send messages to the process using " { $link send } ".\n\n'send' will return immediately after placing the message in the target processes message queue.\n\nA process can get a message from its queue using " { $link receive } ". This will get the most recent message and leave it on the stack. If there are no messages in the queue the process will 'block' until a message is available. When a process is blocked it takes no CPU time at all." { $code "[ receive print ] spawn\n\"Hello Process!\" swap send" } @@ -130,14 +106,9 @@ ARTICLE: { "concurrency" "self" } "Self" "A process can get access to its own process object using " { $link self } " so it can pass it to other processes. This allows the other processes to send messages back. A simple example of using this gets the current process' 'self' and spawns a process which sends a message to it. We then receive the message from the original process:" { $code "self [ \"Hello!\" swap send ] spawn 2drop receive .\n => \"Hello!\"" } ; -ARTICLE: { "concurrency" "servers" } "Servers" -"A common idiom is to create 'server' processes that act on messages that are sent to it. These follow a basic pattern of blocking until a message is received, processing that message then looping back to blocking for a message.\n\nThe following example shows a very simple server that expects an array as its message. The first item of the array should be the senders process object. If the second item is 'ping' then the server sends 'pong' back to the caller. If the second item is anything else then the server exits:" -{ $code ": pong-server ( -- )\n receive {\n { { ?from \"ping\" } [ \"pong\" ?from send pong-server ] }\n { { ?from _ } [ \"server shutdown\" ?from send ] }\n } match-cond ;\n\n[ pong-server ] spawn" } -"Handling the deconstructing of messages and dispatching based on the message can be a bit of a chore. Especially in servers that take a number of different messages. The approach taken above is to use the 'match' library which allows easy deconstructing of messages using " { $link match-cond } "." ; - ARTICLE: { "concurrency" "synchronous-sends" } "Synchronous Sends" -{ $link send } " sends a message asynchronously, and the sending process continues immediately. The 'pong server' example shown previously all sent messages to the server and waited for a reply back from the server. This pattern of synchronous sending is made easier with " { $link send-synchronous } ".\n\nThis word will send a message to the given process and immediately block until a reply is received for this particular message send. It leaves the reply on the stack. Note that it doesn't wait for just any reply, it waits for a reply specifically to this send.\n\nTo do this it wraps the requested message inside a tagged message format using " { $link tag-message } ":" -{ $code "\"My Message\" tag-message .\n => { ...from... ...tag... \"My Message\" }" } +{ $link send } " sends a message asynchronously, and the sending process continues immediately. The 'pong server' example shown previously all sent messages to the server and waited for a reply back from the server. This pattern of synchronous sending is made easier with " { $link send-synchronous } ".\n\nThis word will send a message to the given process and immediately block until a reply is received for this particular message send. It leaves the reply on the stack. Note that it doesn't wait for just any reply, it waits for a reply specifically to this send.\n\nTo do this it wraps the requested message inside a tagged message format using " { $link } ":" +{ $code "\"My Message\" .\n => T{ synchronous f \"My Message\" ...from... ...tag... }" } "The message is wrapped in array where the first item is the sending process object, the second is a unique tag, and the third is the original message. Server processes can use the 'from' to reply to the process that originally sent the message. The tag is used in the receiving server to include the value in the reply. After the send-synchronous call the current process will block waiting for a reply that has the exact same tag. In this way you can be sure that the reply you got was for the specific message sent. Here is the pong-server recoded to use 'send-synchronous':" { $code ": pong-server ( -- )\n receive {\n { { ?from ?tag \"ping\" } [ ?tag \"pong\" 2array ?from send pong-server ] }\n { { ?from _ } [ ?tag \"server shutdown\" 2array ?from send ] }\n } match-cond ;\n\n[ pong-server ] spawn \"ping\" swap send-synchronous .\n => \"pong\"" } "Notice that the code to send the reply back to the original caller wraps the reply in an array where the first item is the tag originally sent. 'send-synchronous' only returns if it receives a reply containing that specific tag." ; @@ -145,27 +116,15 @@ ARTICLE: { "concurrency" "synchronous-sends" } "Synchronous Sends" ARTICLE: { "concurrency" "exceptions" } "Exceptions" "A process can handle exceptions using the standard Factor exception handling mechanism. If an exception is uncaught the process will terminate. For example:" { $code "[ 1 0 / \"This will not print\" print ] spawn" } -"Processes can be linked so that a parent process can receive the exception that caused the child process to terminate. In this way 'supervisor' processes can be created that are notified when child processes terminate and possibly restart them.\n\nThe easiest way to form this link is using " { $link spawn-link } ". This will create a unidirectional link, such that if an uncaught exception causes the child to terminate, the parent process can catch it:" +"Processes can be linked so that a parent process can receive the exception that caused the child process to terminate. In this way 'supervisor' processes can be created that are notified when child processes terminate and possibly restart them.\n\nThe easiest way to form this link is using " { $link spawn-linked } ". This will create a unidirectional link, such that if an uncaught exception causes the child to terminate, the parent process can catch it:" { $code "[\n [ 1 0 / \"This will not print\" print ] spawn-link drop\n receive\n] [ \"Exception caught.\" print ] recover" } "Exceptions are only raised in the parent when the parent does a " { $link receive } " or " { $link receive-if } ". This is because the exception is sent from the child to the parent as a message." ; -ARTICLE: { "concurrency" "futures" } "Futures" -"A future is a placeholder for the result of a computation that is being calculated in a process. When the process has completed the computation the future can be queried to find out the result. If the computation has not completed when the future is queried them the process will block until the result is completed. A future is created using " { $link future } ".\n\nThe quotation will be run in a spawned process, and a future object is immediately returned. This future object can be resolved using " { $link ?future } ".\n\nFutures are useful for starting calculations that take a long time to run but aren't needed until later in the process. When the process needs the value it can use '?future' to get the result or block until the result is available. For example:" -{ $code "[ 30 fib ] future\n...do stuff...\n?future" } ; - -ARTICLE: { "concurrency" "promises" } "Promises" -"A promise is similar to a future but it is not produced by calculating something in the background. It represents a promise to provide a value sometime later. A process can request the value of a promise and will block if the promise is not fulfilled. Later, another process can fulfill the promise, providing a value. All threads waiting on the promise will then resume with that value on the stack. Use " { $link } " to create a promise, " { $link fulfill } " to set it to a value, and " { $link ?promise } " to retrieve the value, or block until the promise is fulfilled:" -{ $code "\n[ ?promise \"Promise fulfilled: \" write print ] spawn drop\n[ ?promise \"Promise fulfilled: \" write print ] spawn drop\n[ ?promise \"Promise fulfilled: \" write print ] spawn drop\n\"hello\" swap fulfill\n => Promise fulfilled: hello\n Promise fulfilled: hello\n Promise fulfilled: hello" } ; - ARTICLE: { "concurrency" "concurrency" } "Concurrency" "The concurrency library is based upon the style of concurrency used in systems like Erlang and Termite. It is built on top of the standard Factor lightweight thread system.\nA concurrency oriented program is one in which multiple processes run simultaneously in a single Factor image or across multiple running Factor instances. The processes can communicate with each other by asynchronous message sends. Although processes can share data via Factor's mutable data structures it is not recommended as the use of shared state concurrency is often a cause of problems." -{ $subsection { "concurrency" "loading" } } { $subsection { "concurrency" "processes" } } { $subsection { "concurrency" "self" } } -{ $subsection { "concurrency" "servers" } } { $subsection { "concurrency" "synchronous-sends" } } -{ $subsection { "concurrency" "exceptions" } } -{ $subsection { "concurrency" "futures" } } -{ $subsection { "concurrency" "promises" } } ; +{ $subsection { "concurrency" "exceptions" } } ; ABOUT: { "concurrency" "concurrency" } diff --git a/extra/concurrency/messaging/messaging-tests.factor b/extra/concurrency/messaging/messaging-tests.factor index 8908506d51..30b88cf16a 100755 --- a/extra/concurrency/messaging/messaging-tests.factor +++ b/extra/concurrency/messaging/messaging-tests.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2005 Chris Double. All Rights Reserved. ! See http://factorcode.org/license.txt for BSD license. ! -USING: kernel concurrency threads vectors arrays sequences +USING: kernel threads vectors arrays sequences namespaces tools.test continuations dlists strings math words match quotations concurrency.private ; IN: temporary diff --git a/extra/concurrency/messaging/messaging.factor b/extra/concurrency/messaging/messaging.factor index bd625ff499..220be64364 100755 --- a/extra/concurrency/messaging/messaging.factor +++ b/extra/concurrency/messaging/messaging.factor @@ -4,14 +4,14 @@ ! Concurrency library for Factor based on Erlang/Termite style ! concurrency. IN: concurrency.messaging -USING: dlists concurrency.threads sequences continuations +USING: dlists threads sequences continuations namespaces random math quotations words kernel arrays assocs init system ; TUPLE: mailbox threads data ; : ( -- mailbox ) - mailbox construct-boa ; + \ mailbox construct-boa ; : mailbox-empty? ( mailbox -- bool ) mailbox-data dlist-empty? ; @@ -52,16 +52,16 @@ PRIVATE> block-if-empty mailbox-data pop-front ; : mailbox-get ( mailbox -- obj ) - f mailbox-timeout-get ; + f mailbox-get-timeout ; : mailbox-get-all-timeout ( mailbox timeout -- array ) - (mailbox-block-if-empty) + block-if-empty [ dup mailbox-empty? ] [ dup mailbox-data pop-back ] [ ] unfold nip ; : mailbox-get-all ( mailbox -- array ) - f mailbox-timeout-get-all ; + f mailbox-get-all-timeout ; : while-mailbox-empty ( mailbox quot -- ) over mailbox-empty? [ @@ -71,7 +71,7 @@ PRIVATE> ] if ; inline : mailbox-timeout-get? ( pred mailbox timeout -- obj ) - [ (mailbox-block-unless-pred) ] 3keep drop + [ block-unless-pred ] 3keep drop mailbox-data delete-node-if ; inline : mailbox-get? ( pred mailbox -- obj ) @@ -83,12 +83,17 @@ TUPLE: linked error thread ; GENERIC: send ( message thread -- ) +: mailbox-of ( thread -- mailbox ) + dup thread-mailbox [ ] [ + dup rot set-thread-mailbox + ] ?if ; + M: thread send ( message thread -- ) - thread-mailbox mailbox-put ; + mailbox-of mailbox-put ; : ?linked dup linked? [ rethrow ] when ; -: mailbox self thread-mailbox ; +: mailbox self mailbox-of ; : receive ( -- message ) mailbox mailbox-get ?linked ; @@ -118,4 +123,4 @@ TUPLE: reply data tag ; receive-if reply-data ; : reply-synchronous ( message synchronous -- ) - [ ] keep synchronous-sender reply ; + [ ] keep synchronous-sender send ; diff --git a/extra/crypto/random.factor b/extra/crypto/random.factor old mode 100644 new mode 100755 index 74dd2dba13..f2d3b0555a --- a/extra/crypto/random.factor +++ b/extra/crypto/random.factor @@ -1,5 +1,5 @@ USING: kernel math math-contrib sequences namespaces errors -hashtables words arrays parser compiler syntax io threads ; +hashtables words arrays parser compiler syntax io ; IN: crypto : make-bits ( quot numbits -- n | quot: -- 0/1 ) 0 -rot [ drop dup call rot 1 shift bitor swap ] each drop ; diff --git a/extra/io/launcher/launcher.factor b/extra/io/launcher/launcher.factor index be4445f842..9b31c78833 100755 --- a/extra/io/launcher/launcher.factor +++ b/extra/io/launcher/launcher.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: io io.backend io.timeouts system kernel namespaces strings hashtables sequences assocs combinators vocabs.loader -init concurrency.threads continuations math ; +init threads continuations math ; IN: io.launcher ! Non-blocking process exit notification facility diff --git a/extra/io/monitors/monitors.factor b/extra/io/monitors/monitors.factor index 2f54ea59fe..274d81a271 100755 --- a/extra/io/monitors/monitors.factor +++ b/extra/io/monitors/monitors.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: io.backend kernel continuations namespaces sequences -assocs hashtables sorting arrays concurrency.threads ; +assocs hashtables sorting arrays threads ; IN: io.monitors r accept r> [ with-client ] 2curry - concurrency:spawn drop + "Client" spawn drop ] 2keep accept-loop ; inline : server-loop ( server quot -- ) @@ -42,7 +42,7 @@ SYMBOL: servers : with-server ( seq service quot -- ) [ V{ } clone servers set - [ spawn-server ] curry concurrency:parallel-each + [ spawn-server ] curry parallel-each ] curry with-logging ; inline : stop-server ( -- ) @@ -65,5 +65,5 @@ SYMBOL: servers : with-datagrams ( seq service quot -- ) [ - [ swap spawn-datagrams ] curry concurrency:parallel-each + [ swap spawn-datagrams ] curry parallel-each ] curry with-logging ; inline diff --git a/extra/io/sockets/sockets-docs.factor b/extra/io/sockets/sockets-docs.factor index 1d40be7b67..9136c3ca22 100755 --- a/extra/io/sockets/sockets-docs.factor +++ b/extra/io/sockets/sockets-docs.factor @@ -1,4 +1,4 @@ -USING: help.markup help.syntax io io.backend concurrency.threads +USING: help.markup help.syntax io io.backend threads strings byte-arrays continuations ; IN: io.sockets diff --git a/extra/io/timeouts/timeouts.factor b/extra/io/timeouts/timeouts.factor index d4106286fd..0bae855399 100755 --- a/extra/io/timeouts/timeouts.factor +++ b/extra/io/timeouts/timeouts.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Slava Pestov, Doug Coleman ! See http://factorcode.org/license.txt for BSD license. USING: kernel math system dlists namespaces assocs init -concurrency.threads io.streams.duplex ; +threads io.streams.duplex ; IN: io.timeouts TUPLE: lapse entry timeout cutoff ; diff --git a/extra/io/unix/backend/backend.factor b/extra/io/unix/backend/backend.factor index 722f38a5af..33f694a018 100755 --- a/extra/io/unix/backend/backend.factor +++ b/extra/io/unix/backend/backend.factor @@ -1,9 +1,10 @@ ! Copyright (C) 2004, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: alien generic assocs kernel kernel.private math -io.nonblocking sequences strings structs sbufs threads unix -vectors io.buffers io.backend io.streams.duplex math.parser -continuations system libc qualified namespaces io.timeouts ; +io.nonblocking sequences strings structs sbufs +threads unix vectors io.buffers io.backend +io.streams.duplex math.parser continuations system libc +qualified namespaces io.timeouts ; QUALIFIED: io IN: io.unix.backend diff --git a/extra/io/unix/bsd/bsd.factor b/extra/io/unix/bsd/bsd.factor index 0ab9f4ed2a..89b0757da5 100755 --- a/extra/io/unix/bsd/bsd.factor +++ b/extra/io/unix/bsd/bsd.factor @@ -2,8 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. IN: io.unix.bsd USING: io.backend io.unix.backend io.unix.kqueue io.unix.select -io.launcher io.unix.launcher namespaces kernel assocs threads -continuations ; +io.launcher io.unix.launcher namespaces kernel assocs +threads continuations ; ! On Mac OS X, we use select() for the top-level ! multiplexer, and we hang a kqueue off of it for process exit diff --git a/extra/io/unix/kqueue/kqueue.factor b/extra/io/unix/kqueue/kqueue.factor index 19005df404..04bb70d57d 100755 --- a/extra/io/unix/kqueue/kqueue.factor +++ b/extra/io/unix/kqueue/kqueue.factor @@ -2,7 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: alien.c-types kernel io.nonblocking io.unix.backend sequences assocs unix unix.kqueue unix.process math namespaces -combinators threads vectors io.launcher io.unix.launcher ; +combinators threads vectors io.launcher +io.unix.launcher ; IN: io.unix.kqueue TUPLE: kqueue-mx events ; diff --git a/extra/io/unix/launcher/launcher.factor b/extra/io/unix/launcher/launcher.factor index 51773515bf..0393b13c7f 100755 --- a/extra/io/unix/launcher/launcher.factor +++ b/extra/io/unix/launcher/launcher.factor @@ -120,8 +120,6 @@ M: unix-io process-stream* ] if ] if ; -: wait-loop ( -- ) - wait-for-processes [ 250 sleep ] when wait-loop ; - : start-wait-thread ( -- ) - [ wait-loop ] "Process reaper" spawn drop ; + [ wait-for-processes [ 250 sleep ] when t ] + "Process reaper" spawn-server drop ; diff --git a/extra/io/unix/linux/linux.factor b/extra/io/unix/linux/linux.factor index 70f8038baf..c38d8c1283 100755 --- a/extra/io/unix/linux/linux.factor +++ b/extra/io/unix/linux/linux.factor @@ -3,8 +3,8 @@ USING: kernel io.backend io.monitors io.monitors.private io.files io.buffers io.nonblocking io.timeouts io.unix.backend io.unix.select io.unix.launcher unix.linux.inotify assocs -namespaces threads continuations init math alien.c-types alien -vocabs.loader ; +namespaces threads continuations init math +alien.c-types alien vocabs.loader ; IN: io.unix.linux TUPLE: linux-io ; diff --git a/extra/io/unix/sockets/sockets.factor b/extra/io/unix/sockets/sockets.factor index 59a9a8ac2e..930240419a 100755 --- a/extra/io/unix/sockets/sockets.factor +++ b/extra/io/unix/sockets/sockets.factor @@ -4,11 +4,11 @@ ! We need to fiddle with the exact search order here, since ! unix::accept shadows streams::accept. IN: io.unix.sockets -USING: alien alien.c-types generic io -kernel math namespaces io.nonblocking parser threads unix -sequences byte-arrays io.sockets io.binary io.unix.backend -io.streams.duplex io.sockets.impl math.parser continuations -libc combinators ; +USING: alien alien.c-types generic io kernel math namespaces +io.nonblocking parser threads unix sequences +byte-arrays io.sockets io.binary io.unix.backend +io.streams.duplex io.sockets.impl math.parser continuations libc +combinators ; : pending-init-error ( port -- ) #! We close it here to avoid a resource leak; callers of diff --git a/extra/io/unix/unix-tests.factor b/extra/io/unix/unix-tests.factor index 4005fb6c09..515077f22b 100755 --- a/extra/io/unix/unix-tests.factor +++ b/extra/io/unix/unix-tests.factor @@ -1,6 +1,6 @@ -USING: io.files io.sockets io kernel threads namespaces -tools.test continuations strings byte-arrays sequences -prettyprint system ; +USING: io.files io.sockets io kernel threads +namespaces tools.test continuations strings byte-arrays +sequences prettyprint system ; IN: temporary ! Unix domain stream sockets diff --git a/extra/io/windows/launcher/launcher.factor b/extra/io/windows/launcher/launcher.factor index 4da8ed4046..6f79388016 100755 --- a/extra/io/windows/launcher/launcher.factor +++ b/extra/io/windows/launcher/launcher.factor @@ -4,7 +4,7 @@ USING: alien alien.c-types arrays continuations destructors io io.windows io.windows.nt.pipes libc io.nonblocking io.streams.duplex windows.types math windows.kernel32 windows namespaces io.launcher kernel sequences windows.errors assocs -splitting system concurrency.threads init strings combinators +splitting system threads init strings combinators io.backend ; IN: io.windows.launcher @@ -147,10 +147,9 @@ M: windows-io kill-process* ( handle -- ) : wait-loop ( -- ) processes get dup assoc-empty? [ drop t ] [ wait-for-processes ] if - [ 250 sleep ] when - wait-loop ; + [ 250 sleep ] when ; : start-wait-thread ( -- ) - [ wait-loop ] "Process wait" spawn drop ; + [ wait-loop t ] "Process wait" spawn-server drop ; [ start-wait-thread ] "io.windows.launcher" add-init-hook diff --git a/extra/io/windows/nt/backend/backend.factor b/extra/io/windows/nt/backend/backend.factor index 09d23e74e4..caf6a31ea0 100755 --- a/extra/io/windows/nt/backend/backend.factor +++ b/extra/io/windows/nt/backend/backend.factor @@ -1,7 +1,7 @@ USING: alien alien.c-types arrays assocs combinators continuations destructors io io.backend io.nonblocking io.windows libc kernel math namespaces sequences -concurrency.threads tuples.lib windows windows.errors +threads tuples.lib windows windows.errors windows.kernel32 strings splitting io.files qualified ascii combinators.lib ; QUALIFIED: windows.winsock diff --git a/extra/io/windows/nt/files/files.factor b/extra/io/windows/nt/files/files.factor index d33465ae76..3541243016 100755 --- a/extra/io/windows/nt/files/files.factor +++ b/extra/io/windows/nt/files/files.factor @@ -1,6 +1,6 @@ USING: continuations destructors io.buffers io.files io.backend io.timeouts io.nonblocking io.windows io.windows.nt.backend -kernel libc math concurrency.threads windows windows.kernel32 +kernel libc math threads windows windows.kernel32 alien.c-types alien.arrays sequences combinators combinators.lib sequences.lib ascii splitting alien strings assocs ; IN: io.windows.nt.files diff --git a/extra/io/windows/nt/sockets/sockets.factor b/extra/io/windows/nt/sockets/sockets.factor index 9f82350f54..eef7476dd5 100755 --- a/extra/io/windows/nt/sockets/sockets.factor +++ b/extra/io/windows/nt/sockets/sockets.factor @@ -2,7 +2,7 @@ USING: alien alien.accessors alien.c-types byte-arrays continuations destructors io.nonblocking io.timeouts io.sockets io.sockets.impl io namespaces io.streams.duplex io.windows io.windows.nt.backend windows.winsock kernel libc math sequences -concurrency.threads tuples.lib ; +threads tuples.lib ; IN: io.windows.nt.sockets : malloc-int ( object -- object ) diff --git a/extra/logging/logging.factor b/extra/logging/logging.factor index 1503e00163..5846515dca 100755 --- a/extra/logging/logging.factor +++ b/extra/logging/logging.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2003, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: logging.server sequences namespaces concurrency +USING: logging.server sequences namespaces concurrency.messaging words kernel arrays shuffle tools.annotations prettyprint.config prettyprint debugger io.streams.string splitting continuations effects arrays.lib parser strings diff --git a/extra/logging/server/server.factor b/extra/logging/server/server.factor index 05029df1d0..e31391e5d5 100755 --- a/extra/logging/server/server.factor +++ b/extra/logging/server/server.factor @@ -2,8 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: namespaces kernel io calendar sequences io.files io.sockets continuations prettyprint assocs math.parser -words debugger math combinators concurrency arrays init -math.ranges strings ; +words debugger math combinators concurrency.messaging +threads arrays init math.ranges strings ; IN: logging.server : log-root ( -- string ) @@ -85,17 +85,16 @@ SYMBOL: log-files log-root directory [ drop rotate-log ] assoc-each ; : log-server-loop ( -- ) - [ - receive unclip { - { "log-message" [ (log-message) ] } - { "rotate-logs" [ drop (rotate-logs) ] } - { "close-logs" [ drop (close-logs) ] } - } case - ] [ error. (close-logs) ] recover - log-server-loop ; + receive unclip { + { "log-message" [ (log-message) ] } + { "rotate-logs" [ drop (rotate-logs) ] } + { "close-logs" [ drop (close-logs) ] } + } case log-server-loop ; : log-server ( -- ) - [ log-server-loop ] spawn "log-server" set-global ; + [ [ log-server-loop ] [ error. (close-logs) ] recover t ] + "Log server" spawn-server + "log-server" set-global ; [ H{ } clone log-files set-global diff --git a/extra/pack/pack.factor b/extra/pack/pack.factor old mode 100644 new mode 100755 index b9b1f6f314..a2958d5bea --- a/extra/pack/pack.factor +++ b/extra/pack/pack.factor @@ -1,7 +1,7 @@ USING: alien alien.c-types arrays assocs byte-arrays inference inference.transforms io io.binary io.streams.string kernel math math.parser namespaces parser prettyprint -quotations sequences strings threads vectors +quotations sequences strings vectors words macros math.functions ; IN: pack diff --git a/extra/space-invaders/space-invaders.factor b/extra/space-invaders/space-invaders.factor index 57c6b23d19..d992df4d8f 100755 --- a/extra/space-invaders/space-invaders.factor +++ b/extra/space-invaders/space-invaders.factor @@ -3,7 +3,7 @@ ! USING: cpu.8080 cpu.8080.emulator openal math alien.c-types sequences kernel shuffle arrays io.files combinators ui.gestures -ui.gadgets ui.render opengl.gl system threads concurrency match +ui.gadgets ui.render opengl.gl system threads match ui byte-arrays combinators.lib ; IN: space-invaders @@ -353,9 +353,10 @@ M: space-invaders update-video ( value addr cpu -- ) ] if ; M: invaders-gadget graft* ( gadget -- ) - dup invaders-gadget-cpu init-sounds - [ f swap set-invaders-gadget-quit? ] keep - [ millis swap invaders-process ] spawn 2drop ; + dup invaders-gadget-cpu init-sounds + f over set-invaders-gadget-quit? + [ millis swap invaders-process ] curry + "Space invaders" spawn drop ; M: invaders-gadget ungraft* ( gadget -- ) t swap set-invaders-gadget-quit? ; diff --git a/extra/tools/interpreter/interpreter.factor b/extra/tools/interpreter/interpreter.factor index 17a3412e93..3be832aec8 100755 --- a/extra/tools/interpreter/interpreter.factor +++ b/extra/tools/interpreter/interpreter.factor @@ -3,7 +3,7 @@ USING: arrays assocs classes combinators sequences.private continuations continuations.private generic hashtables io kernel kernel.private math namespaces namespaces.private prettyprint -quotations sequences splitting strings concurrency.threads +quotations sequences splitting strings threads vectors words ; IN: tools.interpreter diff --git a/extra/tools/threads/threads.factor b/extra/tools/threads/threads.factor index 0690042a3e..aca9e8e649 100755 --- a/extra/tools/threads/threads.factor +++ b/extra/tools/threads/threads.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. IN: tools.threads -USING: concurrency.threads kernel prettyprint prettyprint.config +USING: threads kernel prettyprint prettyprint.config io io.styles sequences assocs namespaces sorting ; : thread. ( thread -- ) diff --git a/extra/ui/tools/interactor/interactor.factor b/extra/ui/tools/interactor/interactor.factor index 791b68246b..e16560b708 100755 --- a/extra/ui/tools/interactor/interactor.factor +++ b/extra/ui/tools/interactor/interactor.factor @@ -3,7 +3,7 @@ USING: arrays assocs combinators continuations documents ui.tools.workspace hashtables io io.styles kernel math math.vectors models namespaces parser prettyprint quotations -sequences sequences.lib strings concurrency.threads listener +sequences sequences.lib strings threads listener tuples ui.commands ui.gadgets ui.gadgets.editors ui.gadgets.presentations ui.gadgets.worlds ui.gestures definitions ; @@ -88,12 +88,12 @@ M: interactor model-changed ] unless drop ; : interactor-yield ( interactor -- obj ) - dup gadget-graft-state first [ + ! dup gadget-graft-state first [ f over set-interactor-busy? - [ set-interactor-thread ] curry suspend - ] [ - drop f - ] if ; + [ set-interactor-thread ] curry suspend ; + ! ] [ + ! drop f + ! ] if ; M: interactor stream-readln [ interactor-yield ] keep interactor-finish ?first ; diff --git a/extra/ui/tools/listener/listener.factor b/extra/ui/tools/listener/listener.factor index 0f6a45de52..e4a7e6e0e8 100755 --- a/extra/ui/tools/listener/listener.factor +++ b/extra/ui/tools/listener/listener.factor @@ -6,7 +6,7 @@ kernel models namespaces parser quotations sequences ui.commands ui.gadgets ui.gadgets.editors ui.gadgets.labelled ui.gadgets.panes ui.gadgets.buttons ui.gadgets.scrollers ui.gadgets.tracks ui.gestures ui.operations vocabs words -prettyprint listener debugger concurrency.threads ; +prettyprint listener debugger threads ; IN: ui.tools.listener TUPLE: listener-gadget input output stack ; diff --git a/extra/ui/tools/walker/walker.factor b/extra/ui/tools/walker/walker.factor index e80d87d591..d27fa3bb04 100755 --- a/extra/ui/tools/walker/walker.factor +++ b/extra/ui/tools/walker/walker.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: arrays assocs ui.tools.listener ui.tools.traceback ui.tools.workspace inspector kernel models namespaces -prettyprint quotations sequences concurrency.threads +prettyprint quotations sequences threads tools.interpreter ui.commands ui.gadgets ui.gadgets.labelled ui.gadgets.tracks ui.gestures ui.gadgets.buttons ui.gadgets.panes prettyprint.config prettyprint.backend diff --git a/extra/ui/ui.factor b/extra/ui/ui.factor index c38ce2b44a..e152ea2fa4 100755 --- a/extra/ui/ui.factor +++ b/extra/ui/ui.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2006, 2007 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: arrays assocs io kernel math models namespaces -prettyprint dlists sequences concurrency.threads sequences words +prettyprint dlists sequences threads sequences words timers debugger ui.gadgets ui.gadgets.worlds ui.gadgets.tracks ui.gestures ui.backend ui.render continuations init combinators hashtables ; diff --git a/extra/ui/windows/windows.factor b/extra/ui/windows/windows.factor index 4f5b9bd6a8..bdb06042ed 100755 --- a/extra/ui/windows/windows.factor +++ b/extra/ui/windows/windows.factor @@ -5,7 +5,7 @@ ui.backend ui.clipboards ui.gadgets.worlds ui.gestures io kernel math math.vectors namespaces prettyprint sequences strings vectors words windows.kernel32 windows.gdi32 windows.user32 windows.opengl32 windows.messages windows.types windows.nt -windows concurrency.threads timers libc combinators +windows threads timers libc combinators continuations command-line shuffle opengl ui.render unicode.case ascii math.bitfields ; IN: ui.windows diff --git a/extra/vocabs/monitor/monitor.factor b/extra/vocabs/monitor/monitor.factor index f22002ee6a..d3e4a44896 100755 --- a/extra/vocabs/monitor/monitor.factor +++ b/extra/vocabs/monitor/monitor.factor @@ -1,18 +1,22 @@ -USING: concurrency.threads io.files io.monitors init kernel -tools.browser ; +! Copyright (C) 2008 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: threads io.files io.monitors init kernel +tools.browser namespaces continuations ; IN: vocabs.monitor ! Use file system change monitoring to flush the tags/authors ! cache -: (monitor-thread) ( monitor -- ) - dup next-change 2drop reset-cache (monitor-thread) ; +SYMBOL: vocab-monitor : monitor-thread ( -- ) - "" resource-path t (monitor-thread) ; + vocab-monitor get-global next-change 2drop reset-cache ; : start-monitor-thread #! Silently ignore errors during monitor creation since #! monitors are not supported on all platforms. - [ monitor-thread ] "Vocabulary monitor" spawn drop ; + [ + "" resource-path t vocab-monitor set-global + [ monitor-thread t ] "Vocabulary monitor" spawn-server drop + ] [ drop ] recover ; [ start-monitor-thread ] "vocabs.monitor" add-init-hook diff --git a/extra/webapps/planet/planet.factor b/extra/webapps/planet/planet.factor index 456855c1fa..e4820c0d59 100755 --- a/extra/webapps/planet/planet.factor +++ b/extra/webapps/planet/planet.factor @@ -1,7 +1,7 @@ -USING: sequences rss arrays concurrency kernel sorting -html.elements io assocs namespaces math threads vocabs html -furnace http.server.templating calendar math.parser splitting -continuations debugger system http.server.responders +USING: sequences rss arrays concurrency.futures kernel sorting +html.elements io assocs namespaces math threads +vocabs html furnace http.server.templating calendar math.parser +splitting continuations debugger system http.server.responders xml.writer prettyprint logging ; IN: webapps.planet