POSI threads eplained part 1分析和总结分析和总结.docxVIP

  • 0
  • 0
  • 约1.74万字
  • 约 10页
  • 2023-04-25 发布于上海
  • 举报

POSI threads eplained part 1分析和总结分析和总结.docx

Disclaimer : Disclaimer : The original version of this article was first published on IBM developerWorks, and is property of Westtech Information Services. This document is an updated version of the original article, and contains various improvements made by the Gentoo Linux Documentation team. This document is not actively maintained. POSIX threads explained, part 1 Content: A simple and nimble tool for memory sharing Threads are fun Knowing how to properly use threads should be part of every good programmers repertoire. Threads are similar to processes. Threads, like processes, are time-sliced by the kernel. On uniprocessor systems the kernel uses time slicing to simulate simultaneous execution of threads in much the same way it uses time slicing with processes. And, on multiprocessor systems, threads are actually able to run simultaneously, just like two or more processes can. So why is multithreading preferable to multiple independent processes for most cooperative tasks? Well, threads share the same memory space. Independent threads can access the same variables in memory. So all of your programs threads can read or write the declared global integers. If youve ever programmed any non-trivial code that uses fork(), youll recognize the importance of this tool. Why? While fork() allows you to create multiple processes, it also creates the following communication problem: how to get multiple processes, each with their own independent memory space, to communicate. There is no one simple answer to this problem. While there are many different kinds of local IPC (inter-process communication), they all suffer from two important drawbacks: They impose some form of additional kernel overhead, lowering performance. In almost all situations, IPC is not a natural extension of your code. It often dramatically increases the complexity of your program. Double bummer: overhead and complication arent good things. If youve ever had to make massive modifications to one of your pro

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档