是什么叉子和线程之间的区别? [英] What is the difference between fork and thread?

查看:101
本文介绍了是什么叉子和线程之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释叉子和线程之间的区别?

Can anyone explain the difference between a fork and a thread?

推荐答案

一个叉子给你一个全新的过程,这是当前进程的副本,与同code段。作为存储器图像变化(通常这是由于这两个过程的不同行为)你得到的存储器中的影像的分离(写时复制),但是可执行code保持不变。除非他们使用一些进程间通信(IPC)任务不共享内存原始的。

A fork gives you a brand new process, which is a copy of the current process, with the same code segments. As the memory image changes (typically this is due to different behaviour of the two processes) you get a separation of the memory images (Copy On Write), however the executable code remains the same. Tasks do not share memory unless they use some Inter Process Communication (IPC) primitive.

在对比度的线程是相同的任务的另一个执行线程。一个任务可以有多个线程和任务内存对象的线程之间共享,因此共享数据必须通过一些原始和同步对象访问(如的互斥条件变量并的信号灯),让您避免数据损坏。

In contrast a thread is another execution thread of the same task. One task can have multiple threads, and the task memory object are shared among threads, therefore shared data must be accessed through some primitive and synchronization objects (like mutexes, condition variables and semaphores) that allow you to avoid data corruption.

这篇关于是什么叉子和线程之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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