3 ms·
On Linux, there is very little distinction between processes and threads. (Assuming you're using the standard POSIX threads implementation, which you probably a
by scott_s 15y ago
On Linux, there is very little distinction between processes and threads. (Assuming you're using the standard POSIX threads implementation, which you probably are.) They are represented by the same data structure in the kernel (the task_struct), hence they are treated the same by the system. Their context switch overhead is the same. The only real difference is that processes get their own address space, which will incur a higher cost at creation time.
If you're talking about threads implemented by a language runtime (which may execute its own concept of threads on top of kernel threads), then the above may not apply. And on Windows, I understand that there is a real difference between threads and processes, although I have no systems programming experience with it.
- samuel 15y agoIt really is performance-wise? Does a process switch between two equal processes avoids a TLB-flush?(How it could?) I don't know, I'm genuinely curious.
- scott_s 15y agoNo, you're correct, I forgot about the TLB.
- dfox 15y agoThe Windows approach to threads is essentially equivalent, both kernels mainly deal with threads that only incidentally belong to processes. While in Linux process is essentially an special case of thread, Windows kernel actually has processes as distinct entities, but that is mostly an implementation detail, to some extent, NT kernel is even more thread-oriented, as there is more state associated with thread (and surprisingly, some things that might look like in-kernel process state from Unix standpoint are actually illusion provided by Windows userspace components).