前言:
现时大家对“linux线程的实现”可能比较关心,朋友们都想要学习一些“linux线程的实现”的相关内容。那么小编同时在网络上收集了一些关于“linux线程的实现””的相关资讯,希望同学们能喜欢,小伙伴们一起来了解一下吧!You know,Linux内核对线程的实现,与Windows内核下的线程实现有很大的不同,Linux对我们是如此的重要,赶快学吧,OK,Let's go!
The Linux Implementation of Threads
Linux has a unique implementation of threads.To the Linux kernel, there is no concept of a thread. Linux implements all threads as standard processes.The Linux kernel does not provide any special scheduling semantics or data structures to represent threads.Instead, a thread is merely a process that shares certain resources with other processes.Each thread has a unique task_struct and appears to the kernel as a normal process—threads just happen to share resources, such as an address space, with other processes.
Linux实现的线程非常独特,从内核的角度来看,并没有线程这样的概念。Linux把所有的线程都当做进程来实现。内核并没有准备特别的调度算法或是定义特别的数据结构来表现线程。相反,线程仅被视为一个与其它进程共享某些资源的进程。每个进程都拥有唯一隶属于自己的task_struct,所以在内核中,它看起来就像是一个普通的进程(只是线程和其它一些进程共享某些资源,如地址空间)。
This approach to threads contrasts greatly with operating systems such as Microsoft
Windows or Sun Solaris, which have explicit kernel support for threads (and sometimes
call threads lightweight processes).The name “lightweight process” sums up the difference in philosophies between Linux and other systems.To these other operating systems, threads are an abstraction to provide a lighter, quicker execution unit than the heavy process.To Linux, threads are simply a manner of sharing resources between processes (which are already quite lightweight).10 For example, assume you have a process that consists of four threads. On systems with explicit thread support, one process descriptor might exist that,in turn, points to the four different threads.The process descriptor describes the shared resources, such as an address space or open files.The threads then describe the resources they alone possess. Conversely, in Linux, there are simply four processes and thus four normal task_struct structures.The four processes are set up to share certain resources. The result is quite elegant.
上述线程机制的实现与Microsoft Widows或是Sun Solaris等操作系统的实现差异非常大。这些系统都在内核中提供了专门支持线程的机制(这些系统常常把线程称作轻量级进程(lightweight processes))."轻量级进程"这种叫法本身就概括了Linux在此处与其它系统的差异,在其它的系统中,相对于重量级的进程,线程被抽象成一种耗费较少资源,运行迅速的执行单元,而对于Linux来说,它只是一种进程间共享资源的手段(Linux的进程本身就够轻量级了),举例来说,假如有一个包含四个线程的进程,在提供专门线程支持的系统中,通常会有一个包含指向四个不同线程的指针的进程描述符。该描述符负责描述像地址空间、打开文件这样的共享资源。线程本身再去描述它独占的资源。相反,Linux 仅仅创建四个进程并分配普通的task_struct结构。建立这四个进程时指定他们共享某些资源,这是相当高雅的做法。
Note:在周志明写的《深入理解Java虚拟机》第三版的第十二章第四小节Java与线程,也对"轻量级进程"有较详细的说明。
You know 反向代理的英文是Reverse Proxy.那正向代理呢?哈哈!Forward Proxy.
标签: #linux线程的实现