进程与线程 [英] Process vs Threads

查看:69
本文介绍了进程与线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何决定是在应用程序中使用线程还是完全创建单独的进程来实现并行性.

How to decide whether to use threads or create separate process altogether in your application to achieve parallelism.

推荐答案

线程重量更轻,对于让几个工人"仅仅利用所有可用的CPU或内核,最好使用线程.

Threads are more light weight, and for the making several "workers" just to utilize all availabe CPUs or cores, you're better of with threads.

与大多数服务器一样,当您需要使工作人员更好地隔离和更强大时,请使用套接字.当一个线程严重崩溃时,它通常会破坏整个进程,包括在该进程中工作的其他线程.如果某个过程变酸死了,则它不会影响其他任何过程,因此他们可以像没有任何事情一样开心地继续忙碌.

When you need the workers to be better isolated and more robust, like with most servers, go with sockets. When one thread crashes badly, it usually takes down the entire process, including other threads working in that process. If a process turns sour and dies, it doesn't touch any other process, so they can happily go on with their bussiness as if nothing happened.

这篇关于进程与线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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