Re: Thread will get garbage collected?

2017-01-17 Thread Rene Zwanenburg via Digitalmars-d-learn
On Tuesday, 17 January 2017 at 08:58:33 UTC, Arun Chandrasekaran wrote: Interesting. Why doesn't the thread get GC'd in this case even without any reference still active? There will be a reference to it in druntime itself: http://dlang.org/phobos/core_thread.html#.Thread.getThis

Re: Thread will get garbage collected?

2017-01-17 Thread ketmar via Digitalmars-d-learn
On Tuesday, 17 January 2017 at 08:58:33 UTC, Arun Chandrasekaran wrote: Interesting. Why doesn't the thread get GC'd in this case even without any reference still active? basically 'cause there is no reliable way to correctly "abort" a thread. nobody knows what is really going on inside it,

Re: Thread will get garbage collected?

2017-01-17 Thread Arun Chandrasekaran via Digitalmars-d-learn
On Tuesday, 17 January 2017 at 08:12:50 UTC, ketmar wrote: import core.thread; import core.time; import std.stdio; void threadStarter (string path) { new Thread({ for (;;) { writeln(path); Thread.sleep(1.seconds); } }).start(); } class A { ~this () { import

Re: Thread will get garbage collected?

2017-01-17 Thread thedeemon via Digitalmars-d-learn
On Monday, 16 January 2017 at 22:08:56 UTC, JN wrote: 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

Re: Thread will get garbage collected?

2017-01-16 Thread kinke via Digitalmars-d-learn
On Monday, 16 January 2017 at 22:08:56 UTC, JN wrote: 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

Thread will get garbage collected?

2017-01-16 Thread JN via Digitalmars-d-learn
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