线程与进程(Process & Threads)
-Process is an infrastructure in which execution takes place (address space + resources)
-Thread is a program component executing within a process context – each thread has its own execution stack
Each thread has:
an execution state运行状态
an execution stack
saved thread context
some static storage for local variables
access to the memory and resources of its process
简单来说就是,首先要有个对应的状态,然后要有执行栈,然后可以在非运行状态保存当前内容以便再次运行,然后可以存贮一些信息,可以被处理器运行
线程的好处:
创建新的线程(Thread)比进程(Process)用时少
终止Thread比Process更快
在两个Thread之间交替更块
thread之间交流更高效
User-Level Threads(ULT)
所有的线程都由应用处理好了
劣势:
当一个ULT锁定了系统调用时,所有的在相同进程中的线程都将被锁定
不能利用多线程的优势
Kernel-Level Threads(KLT)
例如:Windows & Linux
所有工作由kernel完成(项目中没有线程管理)
优势:
劣势:
Combined Approaches
例如: SUN Solaris
**Parallel Execution 平行处理**
Applications That Benefit
Multithreaded native applications
characterized by having a small number of highly threaded processes
Multiprocess applications
characterized by the presence of many single-threaded processes
Java applications
Multiinstance applications
multiple instances of the application in parallel
Hyper-threading
是inter的噫哥主要的处理同时多线程(simultaneous multithreading SMT)一项技术,可以提高x86微处理器的性能。
Hyper-threading = logical core
对于每一个物理存在的处理器,操作系统的地址时两个虚拟的或是逻辑核心,在可能的情况下分享工作量
For each processor core that is physically present, the operating system addresses two virtual or logical cores, and shares the workload between them when possible. The main function of hyper-threading is to increase the number of independent instructions in the pipeline; it takes advantage of superscalar architecture, in which multiple instructions operate on separate data in parallel. With HTT, one physical core appears as two processors to the operating system, which can use each core to schedule two processes at once. In addition, two or more processes can use the same resources: if resources for one process are not available, then another process can continue if its resources are available.