parallel execution
If you need to run an action on all elements of a collection, you can use run!
.
(run! println (range 100))
This will run all of the println
s in sequence. But there's no built-in function to run all of those functions in parallel. That's your task this week.
Write a function runp!
that takes a function and a sequence of arguments. It will run the function on different threads and wait for them all to finish. It returns nil
, just like run!
.
(defn runp! [f coll]
Please be mindful of the number of threads it creates. For instance, if I create 4000 threads on my machine, it crashes the OS. The typical solution is to use a thread pool.