@asterite I repeat my code and record the process as this:
$head -1 test2.sh
set -x
$sh test2.sh
+ cat demo.cr
def test(num : Int32)
num.times do |line|
proc = ->(x : Int32) do
spawn do
# to do something
sleep(0.1)
end
end
proc.call(line)
end
end
test(ARGV[0].to_i)
Fiber.yield
+ echo '# without -Dpreview_mt'
# without -Dpreview_mt
+ crystal build demo.cr -o demo1
+ export CRYSTAL_WORKERS=1
+ CRYSTAL_WORKERS=1
+ ./demo1 100
+ export CRYSTAL_WORKERS=3
+ CRYSTAL_WORKERS=3
+ ./demo1 100
+ export CRYSTAL_WORKERS=1
+ CRYSTAL_WORKERS=1
+ ./demo1 100000
Unhandled exception: Cannot allocate new fiber stack: Cannot allocate memory (Errno)
from /usr/share/crystal/src/crystal/system/unix/fiber.cr:11:5 in 'allocate_stack'
from /usr/share/crystal/src/fiber/stack_pool.cr:27:53 in 'checkout'
from /usr/share/crystal/src/fiber.cr:90:29 in 'initialize'
from /usr/share/crystal/src/fiber.cr:88:3 in 'new'
from /usr/share/crystal/src/concurrent.cr:62:3 in 'spawn'
from demo.cr:4:7 in '->'
from demo.cr:255:3 in 'test'
from demo.cr:14:1 in '__crystal_main'
from /usr/share/crystal/src/crystal/main.cr:106:5 in 'main_user_code'
from /usr/share/crystal/src/crystal/main.cr:92:7 in 'main'
from /usr/share/crystal/src/crystal/main.cr:115:3 in 'main'
from __libc_start_main
from _start
from ???
+ export CRYSTAL_WORKERS=3
+ CRYSTAL_WORKERS=3
+ ./demo1 100000
Unhandled exception: Cannot allocate new fiber stack: Cannot allocate memory (Errno)
from /usr/share/crystal/src/crystal/system/unix/fiber.cr:11:5 in 'allocate_stack'
from /usr/share/crystal/src/fiber/stack_pool.cr:27:53 in 'checkout'
from /usr/share/crystal/src/fiber.cr:90:29 in 'initialize'
from /usr/share/crystal/src/fiber.cr:88:3 in 'new'
from /usr/share/crystal/src/concurrent.cr:62:3 in 'spawn'
from demo.cr:4:7 in '->'
from demo.cr:255:3 in 'test'
from demo.cr:14:1 in '__crystal_main'
from /usr/share/crystal/src/crystal/main.cr:106:5 in 'main_user_code'
from /usr/share/crystal/src/crystal/main.cr:92:7 in 'main'
from /usr/share/crystal/src/crystal/main.cr:115:3 in 'main'
from __libc_start_main
from _start
from ???
+ echo ''
+ echo '# with -Dpreview_mt'
# with -Dpreview_mt
+ crystal build demo.cr -o demo2 -Dpreview_mt
+ export CRYSTAL_WORKERS=1
+ CRYSTAL_WORKERS=1
+ ./demo2 100
+ export CRYSTAL_WORKERS=3
+ CRYSTAL_WORKERS=3
+ ./demo2 100
+ export CRYSTAL_WORKERS=1
+ CRYSTAL_WORKERS=1
+ ./demo2 100000
Unhandled exception: Cannot allocate new fiber stack: Cannot allocate memory (Errno)
from /usr/share/crystal/src/crystal/system/unix/fiber.cr:11:5 in 'allocate_stack'
from /usr/share/crystal/src/fiber/stack_pool.cr:27:53 in 'checkout'
from /usr/share/crystal/src/fiber.cr:90:29 in 'initialize'
from /usr/share/crystal/src/fiber.cr:88:3 in 'new'
from /usr/share/crystal/src/concurrent.cr:62:3 in 'spawn'
from demo.cr:4:7 in '->'
from demo.cr:255:3 in 'test'
from demo.cr:14:1 in '__crystal_main'
from /usr/share/crystal/src/crystal/main.cr:106:5 in 'main_user_code'
from /usr/share/crystal/src/crystal/main.cr:92:7 in 'main'
from /usr/share/crystal/src/crystal/main.cr:115:3 in 'main'
from __libc_start_main
from _start
from ???
+ export CRYSTAL_WORKERS=3
+ CRYSTAL_WORKERS=3
+ ./demo2 100000
Unhandled exception: Cannot allocate new fiber stack: Cannot allocate memory (Errno)
GC Warning: Failed to expand heap by 2691072 bytes
GC Warning: Failed to expand heap by 262144 bytes
GC Warning: Out of Memory! Heap size: 7 MiB. Returning NULL!
Invalid memory access (signal 11) at address 0x6028
[0x559d937ac3e6] *CallStack::print_backtrace:Int32 +118
[0x559d9379efc0] __crystal_sigfault_handler +304
[0x7f16ca42b890] ???
[0x559d937ea8c3] *Pointer(Debug::DWARF::LineNumbers::Row) +227
[0x559d937e9c9d] *Array(Debug::DWARF::LineNumbers::Row) +285
[0x559d937e9b6d] *Array(Debug::DWARF::LineNumbers::Row) +205
[0x559d937e6fcf] *Debug::DWARF::LineNumbers#register_to_matrix<Debug::DWARF::LineNumbers::Sequence, Debug::DWARF::LineNumbers::Register>:Nil +2047
[0x559d937e5070] *Debug::DWARF::LineNumbers#read_statement_program<Debug::DWARF::LineNumbers::Sequence>:Nil +2848
[0x559d937e3970] *Debug::DWARF::LineNumbers#decode_sequences<(UInt32 | UInt64)>:Nil +3856
[0x559d937e2a4c] *Debug::DWARF::LineNumbers#initialize<IO::FileDescriptor+, (UInt32 | UInt64)>:Nil +108
[0x559d937e29a4] *Debug::DWARF::LineNumbers::new<IO::FileDescriptor+, (UInt32 | UInt64)>:Debug::DWARF::LineNumbers +132
[0x559d937a5c08] *CallStack::read_dwarf_sections:(Array(Tuple(UInt64, UInt64, String)) | Nil) +9928
[0x559d937a335d] *CallStack::decode_line_number<UInt64>:Tuple(String, Int32, Int32) +45
[0x559d937a2b6e] *CallStack#decode_backtrace:Array(String) +302
[0x559d937a2a22] *CallStack#printable_backtrace:Array(String) +50
[0x559d937fda9d] *Exception+ +77
[0x559d937d646c] *Crystal::System::print_exception<String, Exception+>:(Int32 | Nil) +220
[0x559d93806b67] *Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32 +455
[0x559d9379c066] main +6
[0x7f16c97d9b97] __libc_start_main +231
[0x559d9379057a] _start +42
[0x0] ???
+ echo 3
3
and the crystal version/liunux version/cpu/memory as this:
$crystal --version
Crystal 0.33.0 [612825a53] (2020-02-14)
LLVM: 8.0.0
Default target: x86_64-unknown-linux-gnu
$cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"
$free -h
total used free shared buff/cache available
Mem: 62G 342M 59G 1.3M 2.5G 61G
Swap: 975M 95M 880M
$lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 12
On-line CPU(s) list: 0-11
Thread(s) per core: 2
Core(s) per socket: 6
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 158
Model name: Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz
Stepping: 10
CPU MHz: 3400.617
BogoMIPS: 6816.00
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 12288K
NUMA node0 CPU(s): 0-11
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts md_clear flush_l1d