I'm not sure why you are asking me about this?<div><br></div><div>The problem I think is with your understanding of the debugger, and sleep states of other threads.</div><div>If you break on a breakpoint to step the program, all threads be stopped. If you step the code one line at a time in the debugger, it will not yield to the other threads while stepping, the new thread will not begin until the current thread has a reason to yield, and you won't see anything.</div>
<div>When you step over the sleep, the program will execute the sleep, which will then cause a wait for some moments, immediately handing the execution to another thread for that time, and during this time the other thread will have opportunity to print their message and exit. Sleep will always yield the current thread immediately, even if you sleep for 0.</div>
<div>With the sleep calls commented out like that, the main thread will not reach a point where it will be forced to yield to another thread, so you won't see it until the end.<br><br>What I expect to happen, without breaking to the debugger, with all sleeps commented out; the 3 prints will happen after the program exits (it will take some time before the main thread yields to the new created threads) .. if you uncomment any of those sleeps, all prints coming before it will print at that time...<br>
<br><div class="gmail_quote">On 8 February 2012 00:28, Oliver Puerto <span dir="ltr"><<a href="mailto:saxo123@gmx.de">saxo123@gmx.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
I have a question concerning threading. I use Visual Studio with the Visual-D plugin. The problem is somehow that when executing the code below "Derived thread running." is displayed 3 times on the console but not before "return 0" is reached. Then "Derived thread running." is displayed 3x all of a sudden, but not each one by one after each other. This looks a bit strange to me.<br>

<br>
When I unquote the Thread.sleeps after every d?.start() "Derived thread running." is displayed immediately on the console when stepping over Thread.sleep with the debugger. When stepping over d*.start() still nothing happens regardless how much time I wait in the debugger till I jump to the next line. I can't make really head or tail of this. I would expect "Derived thread running." to appear on the console somewhen after d?.start() was executed. Thereafter I could do an additional Thread.sleep if I wanted to. But this would not be necessary for any "Derived thread running." message to be displayed on the console.<br>

<br>
I believe there is something with the debugger I don't understand or don't realize. Any suggestions/ideas?<br>
<br>
Thank you, Oliver Plow<br>
<br>
<br>
import std.stdio, core.thread;<br>
<br>
import DerivedThread;<br>
<br>
int main(string[] argv)<br>
{<br>
    DerivedThread dt1 = new DerivedThread();<br>
    dt1.start();<br>
    // Thread.sleep(dur!("seconds")( 1 ));<br>
<br>
    DerivedThread dt2 = new DerivedThread();<br>
    dt2.start();<br>
    // Thread.sleep(dur!("seconds")( 1 ));<br>
<br>
    DerivedThread dt3 = new DerivedThread();<br>
    dt3.start();<br>
    // Thread.sleep(dur!("seconds")( 1 ));<br>
<br>
    Thread.sleep(dur!("seconds")( 4 ));<br>
    return 0;<br>
}<br>
<br>
------------------ DerivedThread.d ------------------<br>
<br>
import std.stdio, core.thread;<br>
<br>
class DerivedThread : Thread {<br>
        this() {<br>
                super( &run );<br>
        }<br>
<br>
private :<br>
        void run() {<br>
                writeln("Derived thread running.");<br>
        }<br>
}<br>
<span class="HOEnZb"><font color="#888888">--<br>
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir<br>
belohnen Sie mit bis zu 50,- Euro! <a href="https://freundschaftswerbung.gmx.de" target="_blank">https://freundschaftswerbung.gmx.de</a><br>
</font></span></blockquote></div><br></div>