Commit ec09f94e authored by Marek Vavrusa's avatar Marek Vavrusa

Fixed on-the-fly zombie thread reclaiming.

Commit refs #53.
parent 531b619e
......@@ -162,6 +162,9 @@ static void *thread_ep (void *data)
debug_dt("dthreads: [%p] thread finished\n", thread);
unit_signalize_change(unit);
debug_dt("dthreads: [%p] thread exited ep\n", thread);
lock_thread_rw(thread);
thread->state |= ThreadJoinable;
unlock_thread_rw(thread);
// Return
return 0;
......@@ -560,6 +563,7 @@ int dt_start_id (dthread_t *thread)
thread->state &= ~ThreadIdle;
thread->state &= ~ThreadDead;
thread->state &= ~ThreadJoined;
thread->state &= ~ThreadJoinable;
// Do not re-create running threads
if (prev_state != ThreadJoined) {
......@@ -605,7 +609,7 @@ int dt_join (dt_unit_t *unit)
}
// Reclaim dead threads, but only fast
/*if(thread->state == ThreadDead) {
if(thread->state & ThreadJoinable) {
unlock_thread_rw(thread);
debug_dt("dthreads: [%p] join: reclaiming thread\n", thread);
pthread_join(thread->_thr, 0);
......@@ -613,8 +617,7 @@ int dt_join (dt_unit_t *unit)
thread->state = ThreadJoined;
} else {
unlock_thread_rw(thread);
}*/
unlock_thread_rw(thread);
}
}
// Unlock unit
......@@ -730,7 +733,6 @@ int dt_repurpose (dthread_t* thread, runnable_t runnable, void *data)
return 0;
}
// Lock thread state changes
pthread_mutex_lock(&unit->_notify_mx);
lock_thread_rw(thread);
......
......@@ -38,10 +38,11 @@ struct dt_unit_t;
*/
enum {
ThreadJoined = 1 << 0, /*!< Thread is finished and joined. */
ThreadCancelled = 1 << 1, /*!< Thread is cancelled, finishing task. */
ThreadDead = 1 << 2, /*!< Thread is finished, waiting to be freed. */
ThreadIdle = 1 << 3, /*!< Thread is idle, waiting for purpose. */
ThreadActive = 1 << 4 /*!< Thread is active, working on a task. */
ThreadJoinable = 1 << 1, /*!< Thread is dead, waiting to be reclaimed. */
ThreadCancelled = 1 << 2, /*!< Thread is cancelled, finishing task. */
ThreadDead = 1 << 3, /*!< Thread is finished, exiting. */
ThreadIdle = 1 << 4, /*!< Thread is idle, waiting for purpose. */
ThreadActive = 1 << 5 /*!< Thread is active, working on a task. */
} dt_state_t;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment