文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>进程和线程的区别

进程和线程的区别

时间:2010-04-07  来源:wangxingchao2010

摘自Advanced Linux Programming. kernel态是没有process/thread的概念的。user space里面才区分彼此。下文中提到的share memory比较有意思。后面看到pthread之间共享信息会总结一下与process直接share memory及通信的不同。
4.6 Processes Vs. Threads For some programs that benefit from concurrency, the decision whether to use processes or threads can be difficult. Here are some guidelines to help you decide which concurrency model best suits your program:       All threads in a program must run the same executable. A child process, on the    n       other hand, may run a different executable by calling an exec function.       An errant thread can harm other threads in the same process because threads    n       share the same virtual memory space and other resources. For instance, a wild       memory write through an uninitialized pointer in one thread can corrupt       memory visible to another thread.       An errant process, on the other hand, cannot do so because each process has a       copy of the program’s memory space.       Copying memory for a new process adds an additional performance overhead    n       relative to creating a new thread. However, the copy is performed only when       the memory is changed, so the penalty is minimal if the child process only reads       memory.       Threads should be used for programs that need fine-grained parallelism. For    n       example, if a problem can be broken into multiple, nearly identical tasks, threads       may be a good choice. Processes should be used for programs that need coarser       parallelism.       Sharing data among threads is trivial because threads share the same memory.    n       (However, great care must be taken to avoid race conditions, as described previ-       ously.) Sharing data among processes requires the use of IPC mechanisms, as       described in Chapter 5.This can be more cumbersome but makes multiple       processes less likely to suffer from concurrency bugs.
相关阅读 更多 +
排行榜 更多 +
狂野飚客3手游下载

狂野飚客3手游下载

赛车竞速 下载
开个滑雪场手游下载

开个滑雪场手游下载

模拟经营 下载
石油猎人手机版下载

石油猎人手机版下载

赛车竞速 下载