Paste: nt pipe race condition?

Author: Phil Dawes
Mode: factor
Date: Wed, 28 Oct 2009 20:49:07
Plain Text |
USING: accessors command-line io io.encodings.binary
io.pipes io.ports kernel math.parser native-thread-test sequences
serialize alien io.backend.windows ;
IN: pipe-race

: pipe>output-handle ( pipe -- integer ) 
    out>> handle>> handle>> alien-address ;

: handle>output-stream ( integer -- stream )
    <alien> <win32-file> <output-port> ;

: make-handle-arg ( handle -- str )
    number>string "-handle=" prepend  ; 

: read-forever ( -- )
    [ deserialize "." write flush ] loop ;

: child-main ( -- )
    (command-line) [ "-handle=" head? ] find nip
    8 tail string>number handle>output-stream
    [ [ "hello!" serialize flush t ] loop ] with-output-stream* ;
    
: run-test ( -- )
    binary <pipe>
    [ pipe>output-handle make-handle-arg
      { "-run=pipe-race" "-quiet" } swap suffix start-vm-in-os-thread drop ] 
    [ [ read-forever ] with-input-stream* ] bi ;

MAIN: child-main

New Annotation

Summary:
Author:
Mode:
Body: