Permalink
Browse files

Switch to list for auxiliary threads

This makes it easy to ensure the ordering. There is a dependency between
the finalizer and the agent thread, because the agent creates an IO
object, so the finalizer needs to be setup.

Using this order makes sure that we run run auxiliary threads setup in a
fifo fashion and teardown in a lifo fashion. We also move the setup of
the finalizer thread before the phase where the agent thread might be
started.
  • Loading branch information...
dbussink committed Jan 18, 2013
1 parent c68ee4d commit 0c1a67fde47c9c2a2ebc5c47469da56feb4143fa
Showing with 15 additions and 14 deletions.
  1. +11 −11 vm/auxiliary_threads.cpp
  2. +2 −2 vm/auxiliary_threads.hpp
  3. +2 −1 vm/environment.cpp
View
@@ -3,11 +3,11 @@
namespace rubinius {
void AuxiliaryThreads::register_thread(AuxiliaryThread* thread) {
- threads_.insert(thread);
+ threads_.push_back(thread);
}
void AuxiliaryThreads::unregister_thread(AuxiliaryThread* thread) {
- threads_.erase(thread);
+ threads_.remove(thread);
}
void AuxiliaryThreads::shutdown(STATE) {
@@ -16,8 +16,8 @@ namespace rubinius {
if(shutdown_in_progress_) return;
shutdown_in_progress_ = true;
- for(std::set<AuxiliaryThread*>::iterator i = threads_.begin();
- i != threads_.end();
+ for(std::list<AuxiliaryThread*>::reverse_iterator i = threads_.rbegin();
+ i != threads_.rend();
++i) {
(*i)->shutdown(state);
}
@@ -31,8 +31,8 @@ namespace rubinius {
if(exec_in_progress_) return;
exec_in_progress_ = true;
- for(std::set<AuxiliaryThread*>::iterator i = threads_.begin();
- i != threads_.end();
+ for(std::list<AuxiliaryThread*>::reverse_iterator i = threads_.rbegin();
+ i != threads_.rend();
++i) {
(*i)->before_exec(state);
}
@@ -41,7 +41,7 @@ namespace rubinius {
void AuxiliaryThreads::after_exec(STATE) {
// We don't guard here on the assumption that only one thread is running
// after execvp() call.
- for(std::set<AuxiliaryThread*>::iterator i = threads_.begin();
+ for(std::list<AuxiliaryThread*>::iterator i = threads_.begin();
i != threads_.end();
++i) {
(*i)->after_exec(state);
@@ -56,8 +56,8 @@ namespace rubinius {
if(fork_in_progress_) return;
fork_in_progress_ = true;
- for(std::set<AuxiliaryThread*>::iterator i = threads_.begin();
- i != threads_.end();
+ for(std::list<AuxiliaryThread*>::reverse_iterator i = threads_.rbegin();
+ i != threads_.rend();
++i) {
(*i)->before_fork(state);
}
@@ -66,7 +66,7 @@ namespace rubinius {
void AuxiliaryThreads::after_fork_parent(STATE) {
// We don't guard here on the assumption that only one thread is running
// after fork() call.
- for(std::set<AuxiliaryThread*>::iterator i = threads_.begin();
+ for(std::list<AuxiliaryThread*>::iterator i = threads_.begin();
i != threads_.end();
++i) {
(*i)->after_fork_parent(state);
@@ -78,7 +78,7 @@ namespace rubinius {
void AuxiliaryThreads::after_fork_child(STATE) {
// We don't guard here on the assumption that only one thread is running
// after fork() call.
- for(std::set<AuxiliaryThread*>::iterator i = threads_.begin();
+ for(std::list<AuxiliaryThread*>::iterator i = threads_.begin();
i != threads_.end();
++i) {
(*i)->after_fork_child(state);
View
@@ -3,7 +3,7 @@
#include "util/thread.hpp"
-#include <set>
+#include <list>
namespace rubinius {
class AuxiliaryThread {
@@ -24,7 +24,7 @@ namespace rubinius {
bool exec_in_progress_;
bool shutdown_in_progress_;
utilities::thread::Mutex mutex_;
- std::set<AuxiliaryThread*> threads_;
+ std::list<AuxiliaryThread*> threads_;
public:
AuxiliaryThreads()
View
@@ -881,6 +881,8 @@ namespace rubinius {
load_platform_conf(runtime);
boot_vm();
+ start_finalizer();
+
load_argv(argc_, argv_);
state->vm()->initialize_config();
@@ -899,7 +901,6 @@ namespace rubinius {
G(rubinius)->set_const(state, "RUNTIME_PATH", String::create(state,
runtime.c_str(), runtime.size()));
- start_finalizer();
load_kernel(runtime);
shared->finalizer_handler()->start_thread(state);

0 comments on commit 0c1a67f

Please sign in to comment.