NodeJs is a single-thread. When I want to work some high cpu tasks, I can use child_process or cluster to work. Now, my question is why NodeJs provide child_process rather than child_thread? Just it is a single-thread?
Asked
Active
Viewed 41 times
1
-
So you're asking why `child_process` is named `child_process` and not `child_thread`, or am I wrong? – Sven Jul 13 '17 at 10:33
-
No no ~ My question is why node provide child_process to create another process rather than provide a method to create another thread for solving the high cpu task ? – Mark Lin Jul 13 '17 at 10:46
-
Possible duplicate of [How to create threads in nodejs](https://stackoverflow.com/questions/18613023/how-to-create-threads-in-nodejs) – Jordan Running Jul 13 '17 at 19:16
1 Answers
1
Nodejs indeed has a single threaded event loop, each child process spawned is a separate single threaded process.
Perhaps that's a reason why this is so.
p.s. internally the engine is multi threaded - read on: How to create threads in nodejs, https://softwareengineeringdaily.com/2015/08/02/how-does-node-js-work-asynchronously-without-multithreading/

Ulysses
- 5,616
- 7
- 48
- 84