! Copyright (C) 2004, 2007 Slava Pestov. ! Copyright (C) 2005 Mackenzie Straight. ! See http://factorcode.org/license.txt for BSD license. IN: threads USING: arrays init hashtables heaps io.backend kernel kernel.private math namespaces sequences vectors io system continuations debugger dlists ; : schedule-thread ( continuation -- ) run-queue push-front ; : schedule-thread-with ( obj continuation -- ) 2array schedule-thread ; : stop ( -- ) walker-hook [ continue ] [ run-queue pop-back dup array? [ first2 continue-with ] [ continue ] if ] if* ; : yield ( -- ) [ schedule-thread stop ] callcc0 ; : sleep ( ms -- ) >fixnum millis + [ schedule-sleep stop ] curry callcc0 ; : in-thread ( quot -- ) [ >r schedule-thread r> [ V{ } set-catchstack { } set-retainstack [ [ print-error ] recover stop ] call-clear ] (throw) ] curry callcc0 ; \ run-queue set-global sleep-queue set-global [ idle-thread ] in-thread ; [ init-threads ] "threads" add-init-hook PRIVATE>