# a small illustration about how to use PF tasks # the word to use is 'fork'. when this word occurs in PF code, a new # task is created. fork takes a single number as an argument. this # number signifies how many atoms are passed from the datastack to the # new task. # the word 'fork' will fork off a new task. this means that at the # moment the word is encountered, two roads are taken: a parent road # and a client road. # PARENT # from the parent side '1 fork' takes one argument of the stack and # returns. similarly '2 fork' takes 2 arguments and returns. # CHILD # from the child side, '1 fork' does the opposite: it will leave only # a single atom on the data stack, and will continue running. '2 fork' # will leave 2, etc.. # for instance: suppose before '1 fork' is called, the data stack # contains 3 number elements: # <3> 100 200 300 # after '1 fork', the parent's data stack will look like: # <2> 100 200 # and the code following the 'fork' word is not executed. # while the child data stack will look like # <1> 300 # with the code following the 'fork' code executed. # so 'fork' splits a data stack in 2 pieces, and gives the top piece # to the client task, and returns the remaining piece to the parent. load-scheduler : fork-demo 1 fork # give one argument to the client task and return # client will continue here with the single argument begin dup p cr # print the atom we got while being created 1000. sleep # sleep for a bit again ; "type '123 fork-demo' to start a single demo task task." p cr interactive