Can processes share threads?

I was asked to post this on the forums and forgot.

Even if its completely useless and unhelpful its still cool to know.

1 Like

Definitely not useless or unhelpful. If you have a question that hasn’t been addressed yet (or have a followup to an existing question), post away.

Short answer: no. Threads are assigned to a specific process and do not migrate among them.

Roughly speaking, a process is a bunch of threads that share a user context – address space, filetable, etc. Since threads that are part of a process have access to the process context including memory, sharing them among processes would leak information between processes. This is contrary to the principle of process isolation. (Sidenote: threads threads can exist without being part of a process – example: the threads in ASST1 are all kernel-only threads.)

A thread represents an execution context. So in one sense it wouldn’t make sense to share them among processes. If a process needs more execution (processing), it can fork off more worker threads of its own or request more CPU time from the kernel. OTOH, if the goal is to share data among processes, what would need to be shared is memory via one of the IPC (interprocess communication) methods – shared memory blocks, pipes, files etc. This of course needs to be managed carefully by the kernel to prevent security and stability problems.

1 Like