如果一个线程在进程中崩溃怎么办? [英] What happens if one thread crashes in a process?

查看:1213
本文介绍了如果一个线程在进程中崩溃怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个菜鸟问题:

1)为什么node.js在单个线程中运行?为什么不使用流程本身呢? 或者在线程而不是进程中运行它有什么优势?

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)如果进程中的线程崩溃了会发生什么(我知道,未处理的异常将导致进程退出),但是如果正确捕获它会发生什么呢?或诸如浮点异常之类的异常. 进程还会崩溃吗?

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?

推荐答案

在这种情况下,我认为您对单线程"的含义有些困惑. Node.js本身利用后台的多个线程来处理异步调用的其他方式.

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.

Node.js核心(JavaScript引擎)是单线程的.缺少多线程和事件循环的可用性使编程变得非常容易.简而言之,您不必处理多线程带来的所有并发问题,这样,您的代码就更具确定性.

Node.js core, the JavaScript engine, is single threaded. The lack of multi threading and the availability of an event loop makes programming a whole lot easier. In short, you don't have to deal with all the concurrency issues that multi threading brings with it your code is a whole lot more deterministic this way.

万一线程崩溃,这到底是一个还是多个完全无关紧要,如果代码崩溃,您最好的希望是程序死了,那么让程序继续运行就没有什么麻烦了以部分损坏的状态运行.想象一下崩溃的线程负责将数据保存到磁盘,现在您的程序可以继续运行,而无需再次保存.

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.

这篇关于如果一个线程在进程中崩溃怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆