4 ms·
You are confusing threads with processes. Processes are isolated and do not share memory. Threads within a process share memory. For example, see https://msdn.
by kbutler 9y ago
You are confusing threads with processes.
Processes are isolated and do not share memory. Threads within a process share memory. For example, see https://msdn.microsoft.com/en-us/library/windows/desktop/ms684841(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/ms6...
Nginx is single-threaded, multiple process: "Each worker process is single-threaded and runs independently" https://www.nginx.com/blog/inside-nginx-how-we-designed-for-performance-scale/ https://www.nginx.com/blog/inside-nginx-how-we-designed-for-...
Erlang code is single threaded. Each Erlang "process" is an isolated, share-nothing single sequence of instructions, and you don't use semaphores, locks, or critical sections in writing Erlang code. The BEAM VM is implemented as a multithreaded process, but this is not exposed to the Erlang code, and Erlang code can be transparently distributed across multiple instances of the BEAM VM (processes) even on separate hosts.
You're correct on node.js, and "basically trying to re-create preemptive threading provided by the OS."
- slackingoff2017 9y agoNginx recently implemented thread pools for blocking operations. The distinction between threads and processes depends on the OS. The "nothing shared" model used in Linux forking actually shares the underlying memory until the processes diverge (copy on write). The difference between this and threads is that threads expose the shared memory by default. IMO the difference between threads and processes is somewhat academic. I don't know much about BEAM
- robotresearcher 9y ago> IMO the difference between threads and processes is somewhat academic. Shared memory vs. isolated memory is a huge difference. You use completely different sync/protection/IPC approaches with each, so programs look very different. And the copy-on-write optimization of logically isolated memory doesn't effect that. The beauty of it is that it speeds up forking and saves memory without changing your IPC-based programming model.
- lmm 9y ago> IMO the difference between threads and processes is somewhat academic. At a linux-implementation level the difference is almost irrelevant. At a code level the difference between your variables being shared by default versus "thread"-local by default is huge.
- castell 9y ago> Erlang code is single threaded. Each Erlang "process" is an isolated, share-nothing single sequence of instructions, and you don't use semaphores, locks, or critical sections in writing Erlang code. The BEAM VM is implemented as a multithreaded process, but this is not exposed to the Erlang code The same is true for PHP. No wonder Facebook developed HHVM for PHP and also uses Erlang with WhatsApp and other parts.
- lou1306 9y agoWell, Whatsapp servers have always been Erlang-based (well before the acquisition by Facebook) but your point stands.