I’ve two noob questions:
1) Why node.js is being run in a single thread? why not it just uses the process itself? OR What are the advantages of running it in a thread instead of process?
2) What happens if a thread in a process crashed (I am aware that, un-handled exception will cause process to exit), but what happens if its properly catch’d ? or with exceptions like Floating point exceptions. will the process also crashes?
Problem courtesy of: rin
I think you’re a bit confused about what “single threaded” means in this case. Node.js itself utilizes multiple threads in the background to handle otherwise blocking calls in an asynchronous manner.
In case a thread crashes it’s completely irrelevant whether this was the only one or one of many, if code crashes the best thing you can hope for is that the program dies with it, nothing would be more troublesome than having you program continuing to run with partly corrupted state. Imagine the thread that crashes was responsible for saving data to disk, and now you program continues to run without ever saving again.
Solution courtesy of: Ivo Wetzel