skynet icon indicating copy to clipboard operation
skynet copied to clipboard

Crystal version doesn't compile with 1.4.1

Open wcazzola opened this issue 2 years ago • 0 comments

As in the subject the Crystal version doesn't compile with version 1.4.1, something has changed. This is how it should be:

`def skynet(c, num, size, div) if size == 1 c.send num else rc = Channel(Int64|Float64).new sum = 0_i64 div.times do |i| sub_num = num + i*(size/div) spawn skynet(rc, sub_num, size/div, div) end div.times do sum += rc.receive end c.send sum end end

c = Channel(Int64|Float64).new start_time = Time.local spawn skynet(c, 0_i64, 1_000_000, 10) result = c.receive end_time = Time.local puts "Result: #{result} in #{(end_time - start_time).total_milliseconds.to_i}ms."`

Note for linux users, the number of allowed threads have to be raised with

sysctl -w vm.max_map_count=10000000

wcazzola avatar May 23 '22 09:05 wcazzola