by usrbinbash · 3y ago · 0 comments
Wrong. Processes pose hurdles via the limits of IPC and control between processes that Threaded applications don't have to bother with. There are ample examples for this in the PEP.
> What Python need is better support for placing native instances in shared memory.
If that were the case, then threading wouldn't exist in the first place. Shared memory is still IPC. It still requires context switching into the Kernel. It still poses problems that threads don't have.
> It still requires context switching into the Kernel.
There is no less context switching between two threads than between two processes.
> It still poses problems that threads don't have.
Hu, no, it's actually the same problem. If you see threads as different processes with heap being mmap'd at the same location, then you're basically 99.9% right, up to some minor process accounting metadata differences.
I am not talking about switching context between the threads of execution. I am talking about a context switch to kernel code simply to access the shared memory. All interactions with SM require syscalls.
So no, I am not "talking nonsense", and yes, communication between multiple processes requires more context switches than communication between threads.
Please enlighten me with the syscall you use to access a shared memory... because there are none.
As far as the kernel is concerned, "memory" is just a set of pages mapped to a process at a specific address. These pages can be anonymous or named (meaning other processes can map them through that name).
There is no syscall, no context switch, involved to read or write memory, named or anonymous. Hell, that's even the whole purpose of memory mapped IO.
As mentioned earlier, there is also no real difference between a thread and a process as far as the kernel is concerned. A thread is just a special case of process which maps its heap to its parent.
Even the word "thread" doesn't really exist for the Linux kernel. We just call these "lightweight processes", because these are just processes with a shared heap.
Oh rly?
https://man7.org/linux/man-pages/man2/shmat.2.html
https://man7.org/linux/man-pages/man2/shmctl.2.html
https://man7.org/linux/man-pages/man2/shmdt.2.html
https://man7.org/linux/man-pages/man2/shmget.2.html
Pretty sure it says something about "System Calls Manual" at the top of all these man pages ;-)
And IO on the SHM once it's attached may look "free", but it isn't. The M-mapping incurs a further overhead which simply doesn't exist for threads: A threads heap space is the same address space as those of it's siblings in the same process.