factor/basis/tools/threads/threads.factor

33 lines
954 B
Factor
Raw Normal View History

2008-02-18 06:07:40 -05:00
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2008-02-18 08:30:16 -05:00
USING: threads kernel prettyprint prettyprint.config
2008-02-21 20:13:11 -05:00
io io.styles sequences assocs namespaces sorting boxes
2008-08-29 18:07:30 -04:00
heaps.private system math math.parser math.order accessors ;
IN: tools.threads
2008-02-18 06:07:40 -05:00
: thread. ( thread -- )
2008-08-30 13:35:14 -04:00
dup id>> pprint-cell
dup name>> over [ write-object ] with-cell
dup state>> [
[ dup self eq? "running" "yield" ? ] unless*
write
] with-cell
2008-02-21 20:13:11 -05:00
[
2008-08-30 13:35:14 -04:00
sleep-entry>> [
key>> nano-count 1000 /i [-] number>string write
" us" write
2008-02-21 20:13:11 -05:00
] when*
] with-cell ;
2008-02-18 06:07:40 -05:00
: threads. ( -- )
standard-table-style [
[
2008-04-11 08:15:26 -04:00
{ "ID:" "Name:" "Waiting on:" "Remaining sleep:" }
2008-02-18 06:07:40 -05:00
[ [ write ] with-cell ] each
] with-row
threads >alist sort-keys values [
2008-02-18 06:07:40 -05:00
[ thread. ] with-row
] each
] tabular-output nl ;