Process/Thread object lifetime
Posted: Tue Apr 11, 2006 9:51 pm
ok, so I have been trying to figure out how I want to do this, and just can't figure out a scheme which i like.
processes/threads are handled in the following way:
a Process is an address space which may own 0 or more threads at any point in ttime, upon successful construction, it will register itself with the "ProcessManager" which is really just a glorified list of Process * objects and some lookup/managment routines.
a Thread is a unit of execution and must have a single owner (the kernel itself has a "KernelProcess" which has no user mode pages). Threads have both "joinable and non-joinable" options.
So my question is this: given that we should keep a both threads and processes around post death for the goal of being able to get the status and potentially "wait for termination". When should the objects be officially destroyed.
clearly a non-joinable thread should be destroyed upon termination, since there is no way to wait for it to terminate and thus get it's status code. but what about joinable, how long should it be around?
Here's my current idea: a joinable thread must be joined at some point and can only be joined by one other thread (you can't have 3 threads waiting on 1). Once thread A successfully waits for B to terminate, B is cleaned up since noone else may join on it. This does leave the issue of the main thread of a process (if there is one) when is it destroyed? upon Process::destroy() call?
Then there is the issue of when do I destroy a Process object? I do plan on enforcing the idea that a thread from process A cannot wait for a thread in process B (it could wait for process A to complete though). So I could safely destroy all threads in a process when it is officially destroyed...but when is this? not when the "exit_process(int);" syscall is executed, because I still at the very least need the basics of the process object in order to get it's information. I suppose exit_process(int) could destroy the address space itself (reclaim pages) and destroy all child threads..but that still leaves the Process object still lying around...do I just leave it until I NEED the memory/pid?
what do you guys do?
proxy
processes/threads are handled in the following way:
a Process is an address space which may own 0 or more threads at any point in ttime, upon successful construction, it will register itself with the "ProcessManager" which is really just a glorified list of Process * objects and some lookup/managment routines.
a Thread is a unit of execution and must have a single owner (the kernel itself has a "KernelProcess" which has no user mode pages). Threads have both "joinable and non-joinable" options.
So my question is this: given that we should keep a both threads and processes around post death for the goal of being able to get the status and potentially "wait for termination". When should the objects be officially destroyed.
clearly a non-joinable thread should be destroyed upon termination, since there is no way to wait for it to terminate and thus get it's status code. but what about joinable, how long should it be around?
Here's my current idea: a joinable thread must be joined at some point and can only be joined by one other thread (you can't have 3 threads waiting on 1). Once thread A successfully waits for B to terminate, B is cleaned up since noone else may join on it. This does leave the issue of the main thread of a process (if there is one) when is it destroyed? upon Process::destroy() call?
Then there is the issue of when do I destroy a Process object? I do plan on enforcing the idea that a thread from process A cannot wait for a thread in process B (it could wait for process A to complete though). So I could safely destroy all threads in a process when it is officially destroyed...but when is this? not when the "exit_process(int);" syscall is executed, because I still at the very least need the basics of the process object in order to get it's information. I suppose exit_process(int) could destroy the address space itself (reclaim pages) and destroy all child threads..but that still leaves the Process object still lying around...do I just leave it until I NEED the memory/pid?
what do you guys do?
proxy