Threading bugs

Tristam MacDonald swiftcoder at gmail.com
Tue Jun 26 14:36:29 PDT 2007


Oh cripes, right, with that fixed your wait solution works fine, but I still can't find why destructors are not  called at termination with threads?

Johan Granberg Wrote:

> Tristam MacDonald wrote:
> 
> > Hmm, I don't see anything relevant in either the changelog or the news
> > group (haven't finished searching the latter though).
> > 
> > I am not sure I understand, shouldn't all remaining objects have their
> > destructors called when the program exits? What would happen if the object
> > had a non trivial destructor (dispose of shared memory, flush an iostream,
> > etc.)?
> > 
> > The point I don't understand, is why is this only the case when I am using
> > threads? And I think the thread implementation may be a little buggy here
> > anyway, why on earth would the assert statement below cause a 'Bus Error'?
> 
> Because you are redeclaring worker in the Main constructor, change this line
>  Thread worker = new Thread(&workerMain);
> to this
>  worker = new Thread(&workerMain);
> 
> and it will probably work.
> 
> > class Main
> > {
> > this() {
> > writefln("starting");
> > 
> > Thread worker = new Thread(&workerMain);
> > worker.start();
> > }
> > ~this() {
> > writefln("ending");
> > }
> > 
> > int workerMain()
> > {
> > writefln("In Thread");
> > return 0;
> > }
> > 
> > Thread worker;
> > }
> > 
> > int main()
> > {
> > Main m = new Main();
> > 
> > assert(m.worker.getState() == Thread.TS.TERMINATED, "Thread not done!");
> > 
> > return 0;
> > }
> 



More information about the Digitalmars-d-learn mailing list