I'm looking at the example code for core.thread Thread class:
new Thread({
// Codes to run in the newly created thread.
}).start();
let's imagine I put the code in a function:
void loadFileAsync(string path)
{
new Thread({
writeln(readText(path)); // imagine the file is
big so it takes some time
}).start();
}
void main()
{
loadFileAsync("foo.txt");
}
Am I correctly understanding, that after going out of scope, it's
possible for GC to destroy my thread before the file finishes
loading? How to prevent GC from destroying my thread before it
finishes and make sure the file is loaded completely?