Welcome to the CHICKEN Scheme pasting service

asynchronous processes pasted by mario-goulart on Sat Sep 1 20:57:42 2012

(use posix srfi-18)

(define (process& cmd . args)
  (thread-start!
   (make-thread
    (lambda ()
      (print "Running " cmd)
      (let-values (((in out pid) (process cmd args)))
        (let loop ()
          (let-values (((pid exit? status) (process-wait pid 'nohang)))
            (if (zero? pid)
                (begin
                  (thread-sleep! 0.01)
                  (loop))
                (and exit? status)))))))))


(let ((s1 (process& "/bin/sleep" "2"))
      (s2 (process& "/bin/sleep" "2")))
  (pp (thread-join! s1))
  (pp (thread-join! s2)))

asynchronous processes with pipes added by mario-goulart on Sat Sep 1 22:34:50 2012

;; Suggested by DerGreatMoritz


(use posix)

(define (async thunk)
  (receive (in out) (create-pipe)
    (process-fork
     (lambda ()
       (file-close in)
       (thunk)
       (file-close out)))
    (file-close out)
    in))

(define (wait fd)
  (file-select (list fd) (list))
  (file-close fd))

(define proc1
  (async (lambda ()
           (print "Hi from proc1")
           (system "sleep 2")
           (print "proc1 done sleeping 2 secs"))))

(define proc2
  (async (lambda ()
           (print "Hi from proc2")
           (system "sleep 1")
           (print "proc2 done sleeping 1 sec"))))

(wait proc1)
(wait proc2)

(print "all done!")

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Which module provides `string-intersperse'?
Visually impaired? Let me spell it for you (wav file) download WAV