Threading bugs
Sean Kelly
sean at f4.ca
Tue Jun 26 21:45:42 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.)?
Running the dtors of all objects on exit is problematic. Should they
run before or after the module dtors? What if they are run after the
module dtors but the object in question relied on the module's dtor not
yet having been run? In Tango, uncollected objects not specifically
cleaned up in a module dtor are not guaranteed to be collected for this
reason. An alternative would be to run a collection after main() exits
as a part of the cleanup process. This would get your Main object
below, but it would slow the shutdown process for the sake of collecting
only a very few objects, and I'm not sure it's worthwhile to do so.
> 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'?
I have no idea. On Tango, your program outputs:
starting
In Thread
Here's the converted code:
import tango.core.Thread;
import tango.stdc.stdio;
class Main
{
this() {
printf("starting\n");
Thread worker = new Thread(&workerMain);
worker.start();
}
~this() {
printf("ending\n");
}
void workerMain()
{
printf("In Thread\n");
}
Thread worker;
}
int main()
{
Main m = new Main();
return 0;
}
Sean
More information about the Digitalmars-d-learn
mailing list