From f64d6c857bde9c525f3f49bdac5ae9bcbd2e63ac Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 9 Nov 2010 15:46:16 -0700 Subject: [PATCH] clean up OS resources immediately upon thread exit Previously, we waited until the next GC to do this, but that can be too long for workloads which create a lot of short-lived threads but don't do much allocation. --- src/machine.cpp | 16 ++++++++++++++-- src/machine.h | 6 +++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index 01b766de93..fedbf9c35f 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -45,7 +45,11 @@ void join(Thread* t, Thread* o) { if (t != o) { - o->systemThread->join(); + if (o->state != Thread::ZombieState + and o->state != Thread::JoinedState) + { + o->systemThread->join(); + } o->state = Thread::JoinedState; } } @@ -2281,6 +2285,12 @@ Thread::exit() } else { threadPeer(this, javaThread) = 0; enter(this, Thread::ZombieState); + + lock->dispose(); + lock = 0; + + systemThread->dispose(); + systemThread = 0; } } } @@ -2288,7 +2298,9 @@ Thread::exit() void Thread::dispose() { - lock->dispose(); + if (lock) { + lock->dispose(); + } if (systemThread) { systemThread->dispose(); diff --git a/src/machine.h b/src/machine.h index 4bdfccfc24..8d861717ef 100644 --- a/src/machine.h +++ b/src/machine.h @@ -2746,7 +2746,11 @@ notifyAll(Thread* t, object o) inline void interrupt(Thread*, Thread* target) { - target->systemThread->interrupt(); + if (target->state != Thread::ZombieState + and target->state != Thread::JoinedState) + { + target->systemThread->interrupt(); + } } inline void