[Issue 4307] spawn()'ed thread doesn't terminate
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Tue Nov  2 20:34:51 PDT 2010
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=4307
--- Comment #5 from Jonathan M Davis <jmdavisProg at gmx.com> 2010-11-02 20:33:50 PDT ---
Actually, the program I posted earlier was buggy (that's what I get for
simplifying code and not studying the simplified version enough, I guess).
Here's the corrected version:
import std.concurrency;
import std.stdio;
void main()
{
    int currThreads = 0;
    enum maxThreads = 6;
    size_t totalThreads = 0;
    auto recProc = (Tid tid)
                   {
                       writeln(++totalThreads);
                       --currThreads;
                   };
    for(size_t i = 0; i < 1_000; ++i)
    {
        if(currThreads < maxThreads)
            receiveTimeout(1, recProc);
        else
            receive(recProc);
        spawn(&threadFunc, thisTid);
        ++currThreads;
    }
    while(currThreads > 0)
        receive(recProc);
}
void threadFunc(Tid parentTid)
{
    send(parentTid, thisTid);
}
-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
    
    
More information about the Digitalmars-d-bugs
mailing list