3 ms·
I do not think your model of threads and processes is correct. Processes have different address spaces whereas threads share an address space. Context switching
by Shoop 6y ago
I do not think your model of threads and processes is correct. Processes have different address spaces whereas threads share an address space. Context switching between threads is much cheaper than context switching between processes because you do not have to swap page tables and do a tlb flush. tlb flushes are extremely expensive. I also think you are misunderstanding how mmap works. mmap is not related to thread spawning.
- mypalmike 6y agoNot the parent, but... mmap is related to thread spawning (well, process forking) in that using the MAP_SHARED flag will result in a pointer that is valid shared memory for both the parent process and any forked processes.
- gmueckl 6y agoIf you stick to one process per core, the number of TLB flushes doesn't change. You can set processor affinity to make sure of that. If you create more threads/processes than cores, you might be able to get measurable impact. I don't understand your comment about mmap. It is often used to share memory between related processes.