summaryrefslogtreecommitdiff
path: root/kern/thread_i.h
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-08-23 21:57:22 +0200
committerRichard Braun <rbraun@sceen.net>2017-08-23 21:57:22 +0200
commit1fcd8e7e40c3c10b4b694be3786b8a9cb7a38391 (patch)
tree16cf532032a48dbc784adc5cafc855fab38b9c69 /kern/thread_i.h
parent079e1f89354dd275d2a2096f3df5d0ddfd24bb12 (diff)
kern/thread: really fix termination
Change the semantics of thread_join so that it not only waits for thread_exit but also for the last reference to be dropped.
Diffstat (limited to 'kern/thread_i.h')
-rw-r--r--kern/thread_i.h17
1 files changed, 9 insertions, 8 deletions
diff --git a/kern/thread_i.h b/kern/thread_i.h
index 7cbd3c7..cd34977 100644
--- a/kern/thread_i.h
+++ b/kern/thread_i.h
@@ -173,16 +173,17 @@ struct thread {
* Members related to termination.
*
* The termination protocol is made of two steps :
- * 1/ The thread exits, thereby reporting that it is exiting while
- * holding the join lock. This includes waking up any thread
- * currently joining.
- * 2/ The thread sets its state to dead and calls the scheduler.
- * The join operation polls the state, and releases a reference
- * when it sees the dead state.
+ * 1/ The thread exits, thereby releasing its self reference, and
+ * sets its state to dead before calling the scheduler.
+ * 2/ Another thread must either already be joining, or join later.
+ * When the thread reference counter drops to zero, the terminating
+ * flag is set, and the joining thread is awaken, if any. After that,
+ * the join operation polls the state until it sees the target thread
+ * as dead, and then releases its resources.
*/
struct thread *join_waiter; /* (j) */
struct spinlock join_lock;
- bool exiting; /* (j) */
+ bool terminating; /* (j) */
struct task *task; /* (T) */
struct list task_node; /* (T) */
@@ -192,7 +193,7 @@ struct thread {
#define THREAD_ATTR_DETACHED 0x1
-void thread_destroy(struct thread *thread);
+void thread_terminate(struct thread *thread);
/*
* Flag access functions.