Thread fails to start

Sean Kelly sean at invisibleduck.org
Sun Jan 2 09:41:07 PST 2011


Adam Conner-Sax Wrote:

> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
> > On 01/01/2011 06:02 PM, Adam Conner-Sax wrote:
> > > As a way to learn D, I am writing a quick test setup for examining different
> > > ways of passing data from one set of threads to another.  I am trying a few
> > > kinds of queues (resizeable array with locking, linked list with locking and
> > > lockfree with cas) and trying to also add message passing and then compare
> > > performance.
> > >
> > > Anyway, I'm running into an odd case where a thread fails to start.  The code
> > > simply hangs in the Threadgroup.create(...) call. I am printing (with
> > > unbuffered i/o) right before the call to "create" and then as soon as the
> > > threadfunction starts so as far as I can tell, the "create" call is made but
> > > the threadfunc never starts and "create" never returns.

What OS are you using?  ThreadGroup.create is extremely simple, the problem is almost definitely in either the thread startup code itself or in the preamble of your supplied thread routine.  What would be great is if you could produce a minimal repro.  The full source you included is a bit much to easily figure out where the problem may be.

> > > It's repeatable but doesn't happen every time the queue is used. It happens
> > > sometimes when the queue is locking and sometimes when it is lockfree. I'd be
> > > happy to post code but for now I thought I'd just see if anyone can think of
> > > why that might happen or can provide some ideas for how to debug it.
> > >
> > > The code always starts the one consumer thread (via spawn. I'm learning!),
> > > then loops over the producers and creates them in a threadgroup just so I can
> > > do a "joinAll" to wait for them to finish.  Also, when the problem occurs,
> > > it's always the first producer thread that fails.  I never get 2 out of 4
> > > started, e.g.

If you're using std.concurrency then don't start threads manually using core.thread.  The mailbox for a thread is created by spawn, and you'll get a segfault trying to send a message to a thread started using core.thread.  I could change this to throw an exception instead though.

> So, in the normal case, I get matched "creating & starting..." and "started" and
> "in produce()"
> 
> In the case where it hangs, all I get is "Creating and starting..." and then it
> stays forever (or as long as I have patience to leave it).

I tried this twice.  The first time I got partway into the third test and got a bus error.  The second time (run via GDB) I have this on my screen and it's been this way for a while now:

F,LL,Lk	  8.87	64.41	970.64	 0	50566	 1.91	4512.36
starting consumer
started.
creating & starting producer
in consume(...)
in produce(...)

Seems different from what you've experienced.


More information about the Digitalmars-d mailing list