How to get return value of every spawn process iteration
Posted: Mon Jun 25, 2018 1:40 pm
Hi all,
Greeting from me! I am a newbie of newLISP, and want to implement a simple feature which launches processes according to CPU number:
I know following code will let p gets only one result:
I want to use an array to hold every process's return value, but following code is not invalid:
So how can I get return value of every spawn process iteration in for-loop? Thanks very much in advance!
Best Regards
Nan Xiao
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