Greeting from me! I am a newbie of newLISP, and want to implement a simple feature which launches processes according to CPU number:
Code: Select all
(import "libc.so" "sysconf")
(constant '_SC_NPROCESSORS_ONLN 503)
(define (report pid)
(println "process: " pid " has returned"))
(define cpu-num (sysconf _SC_NPROCESSORS_ONLN))
(set 'result-array cpu-num)
(dotimes (i cpu-num)
(spawn 'p (println i)))
(until (true? (sync 10 report)))
(exit)
Code: Select all
(dotimes (i cpu-num)
(spawn 'p (println i)))
Code: Select all
(set 'result-array cpu-num)
(dotimes (i cpu-num)
(spawn (result-array i) (println i)))
Best Regards
Nan Xiao