rt: Change the way the kernel exits to avoid pthread leaks

This makes the kernel join every scheduler thread before exiting in order to
ensure that all threads are completely terminated before the process exits. On
my machine, for 32-bit targets, this was causing regular valgrind errors.
This commit is contained in:
Brian Anderson
2012-02-27 13:36:54 -08:00
parent e4c027446e
commit b3f77bf927
5 changed files with 42 additions and 26 deletions

View File

@@ -59,17 +59,21 @@ rust_scheduler::destroy_task_threads() {
void
rust_scheduler::start_task_threads()
{
// Copy num_threads because it's possible for the last thread
// to terminate and have the kernel delete us before we
// hit the last check against num_threads, in which case
// we would be accessing invalid memory.
uintptr_t num_threads = this->num_threads;
for(size_t i = 0; i < num_threads; ++i) {
rust_task_thread *thread = threads[i];
thread->start();
}
}
void
rust_scheduler::join_task_threads()
{
for(size_t i = 0; i < num_threads; ++i) {
rust_task_thread *thread = threads[i];
thread->join();
}
}
void
rust_scheduler::kill_all_tasks() {
for(size_t i = 0; i < num_threads; ++i) {