Program exit is delayed using pthreads

I have a main() that starts some threads similar to:

1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
thread t1, t2, t3;
t1.start();
..
t3.start();
t1.join();
..
t3.join();
printf("done");
return 0;
}


In the threads, I do some work and some sleeping (using select()). Anyway, when my threads are done and have joined main thread, I see the final "done" message, and I assume return 0 is called, but I get a delay of several seconds before my program actually exits (i.e. returns focus to command prompt). The delay varies from maybe 5-15 seconds. It's strange...my threads have fully exited I assume because they have joined, and my main() shouldn't be doing anything else. Anyone got a clue on this one?
Just to update, i did sort of resolve this problem. It has to do with where I returned.

Old code:
1
2
3
4
5
6
7
int main()
try {
//thread stuff
}
catch{}
exit(0);
}


New code:
1
2
3
4
5
6
7
int main()
try{
//thread stuff
exit(0);
}
catch{}
}
Topic archived. No new replies allowed.