rt: Detach pthreads before exiting

Joinable pthreads need to be either joined or detached and we no
longer join with the scheduler threads.
This commit is contained in:
Brian Anderson
2012-02-09 16:13:56 -08:00
parent 5d8d591ffc
commit 81e1564a7d
3 changed files with 16 additions and 2 deletions

View File

@@ -319,6 +319,7 @@ rust_task_thread::create_task(rust_task *spawner, const char *name,
void rust_task_thread::run() { void rust_task_thread::run() {
this->start_main_loop(); this->start_main_loop();
detach();
sched->release_task_thread(); sched->release_task_thread();
} }

View File

@@ -4,6 +4,9 @@
rust_thread::rust_thread() : thread(0) { rust_thread::rust_thread() : thread(0) {
} }
rust_thread::~rust_thread() {
}
#if defined(__WIN32__) #if defined(__WIN32__)
static DWORD WINAPI static DWORD WINAPI
#elif defined(__GNUC__) #elif defined(__GNUC__)
@@ -41,3 +44,12 @@ rust_thread::join() {
#endif #endif
thread = 0; thread = 0;
} }
void
rust_thread::detach() {
#if !defined(__WIN32__)
// Don't leak pthread resources.
// http://crosstantine.blogspot.com/2010/01/pthreadcreate-memory-leak.html
pthread_detach(thread);
#endif
}

View File

@@ -12,6 +12,8 @@ public:
pthread_t thread; pthread_t thread;
#endif #endif
rust_thread(); rust_thread();
virtual ~rust_thread();
void start(); void start();
virtual void run() { virtual void run() {
@@ -19,8 +21,7 @@ public:
} }
void join(); void join();
void detach();
virtual ~rust_thread() {} // quiet the compiler
}; };
#endif /* RUST_THREAD_H */ #endif /* RUST_THREAD_H */