Threading bugs
Johan Granberg
lijat.meREM at OVEgmail.com
Tue Jun 26 14:32:58 PDT 2007
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