diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-02-27 13:36:54 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-02-27 14:25:32 -0800 |
| commit | b3f77bf92703543793a8073c8319e461e024cb69 (patch) | |
| tree | f32f999cc958d5c5a9d496025be4d5c31ca1b5ee /src/rt/rust_scheduler.cpp | |
| parent | e4c027446ec0d985be98dcbdce2b80308b88b12a (diff) | |
| download | rust-b3f77bf92703543793a8073c8319e461e024cb69.tar.gz rust-b3f77bf92703543793a8073c8319e461e024cb69.zip | |
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.
Diffstat (limited to 'src/rt/rust_scheduler.cpp')
| -rw-r--r-- | src/rt/rust_scheduler.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/rt/rust_scheduler.cpp b/src/rt/rust_scheduler.cpp index 629df420bd1..c2906bc51a0 100644 --- a/src/rt/rust_scheduler.cpp +++ b/src/rt/rust_scheduler.cpp @@ -59,11 +59,6 @@ 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(); @@ -71,6 +66,15 @@ rust_scheduler::start_task_threads() } 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) { rust_task_thread *thread = threads[i]; |
