Reputation: 590
I have just added threads to an existing program using a model I have used before but this time the thread did not execute so I added
Thread.new {puts "thread" }
exit
at the top of the program and it exited without printing anything.
Pointers on diagnosing the problem solicited.
Linux (ubuntu) ruby 2.7
Upvotes: 3
Views: 52
Reputation: 17528
The given code ..
Thread.new {puts "thread" }
exit
.. is not guaranteed to execute the puts
. You must join
the thread.
t = Thread.new {puts "thread" }
t.join # block until thread finishes
exit
Upvotes: 3