简体   繁体   English

时间片如何在进程中的pthreads之间划分?

[英]How is time slice divided among the pthreads in a process?

Is the Linux kernel aware of pthreads in the user address space ( which i dont think it is..but i did not find any info abt that). Linux内核是否知道用户地址空间中的pthreads(我不认为它是..但我没有找到任何信息)。 How does the Instruction pointer change when thread switching takes place.. ?? 当线程切换发生时,指令指针如何改变。

The native NPTL (native posix thread library) used in Linux maps pthreads to "processes that share resources and therefore look like threads" in the kernel. Linux中使用的本机NPTL(本机posix线程库)将pthreads映射到内核中的“共享资源并因此看起来像线程的进程”。 In this way, the kernel's scheduler directly controls the scheduling of pthreads. 通过这种方式,内核的调度程序直接控制pthread的调度。

A "pthread switch" is done by the exact same code (in the kernel) that handles process switches. “pthread开关”由处理进程切换的完全相同的代码(在内核中)完成。 Simplified, this would be something like "store previous process state; if the next process uses a different virtual address space then switch virtual address spaces; load next process state;" 简化后,这将类似于“存储先前的进程状态;如果下一个进程使用不同的虚拟地址空间,则切换虚拟地址空间;加载下一个进程状态;” (where "process state" includes the instruction pointer for the process/thread). (其中“进程状态”包括进程/线程的指令指针)。

Well the Linux kernel doesn't know about user threads (pthread does in userspace, moreover the kernel doesn't really care about them except it just needs to know what to schedule). 那么Linux内核不知道用户线程(pthread在用户空间中做了,而且内核并不真正关心它们,除了它只需要知道要安排什么)。

The instruction pointer is changed in the kernel during what's called a context switch. 在所谓的上下文切换期间,内核中的指令指针被更改。 During this switch the kernel essentially asks the scheduler what's next? 在此切换期间,内核基本上要求调度程序下一步是什么? the scheduler will hand it a task_struct which contains all the information about the thread and the interrupt handler for a context switch will go ahead and set the values on the CPU accordingly (page tables, instruction pointer, etc...) and when that code is done the CPU simply just starts executing from there. 调度程序将为其提供一个task_struct,其中包含有关线程的所有信息,并且上下文切换的中断处理程序将继续并相应地设置CPU上的值(页表,指令指针等)以及何时该代码完成CPU只是从那里开始执行。

1) The kernel doesn't know about user-level threads. 1)内核不了解用户级线程。 However, NPTL isn't user level 但是,NPTL不是用户级别

2) This is a really broad question. 2)这是一个非常广泛的问题。 You should look at an OS book. 你应该看一本OS书。 It will go into depth on that issue and all other involved in a context switch. 它将深入讨论该问题以及所有其他涉及上下文切换的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM