1. Parallelism

Note
Compiling for Parallelism is EXPERIMENTAL - see:
https://crystal-lang.org/2019/09/06/parallelism-in-crystal.html
  • To compiling for parallelism (multiple CPUs) add: -Dpreview_mt to the compile command as shown bellow:

$ crystal build -Dpreview_mt main.cr

Run using:

$ ./main                    # default is to run with 4 CPUs
$ CRYSTAL_WORKERS=8 ./main  # this case run will use 8 CPUs

Now if you need to ensure a Fiber is in the same thread you must use:

spawn same_thread: true do
  # ...
end