Threading bugs
Tristam MacDonald
swiftcoder at gmail.com
Tue Jun 26 14:45:02 PDT 2007
Would explicitly running a full collect cycle at the end of main (and wrapping logic in an inner function work around this? More likely some would still be left though.
Johan Granberg Wrote:
> Tristam MacDonald wrote:
>
> > 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?
>
> An old newsgroup post by Walter
> http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=11455
> i don't like this behavior myself but that's it.
>
> > 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