September 2017
Beginner
402 pages
9h 52m
English
When creating a new thread, it is possible to set the app_lifetime attribute, which requests that the thread lives until the end of the main program. Otherwise it will be terminated after its body is executed. To add this flag, either add it as :app_lifetime or by explicitly passing the True value to the constructor—app_lifetime => True:
Thread.new( name => 'Long thread', code => sub { say 'OK'; }, :app_lifetime,).run().join();say 'Done';
It is important to wait for the thread (using either the finish or join method). Otherwise the main thread may stop executing before the thread returns.
Read now
Unlock full access