如何N'LT; - > 1线程模型的工作? [英] How does N<->1 threading model work?

查看:230
本文介绍了如何N'LT; - > 1线程模型的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在延续<一个href=\"http://stackoverflow.com/questions/26324668/why-does-os-require-maintain-kernel-threads\">question,这是N-1线程模型的其他查询。

据教导说,设计一个应用程序之前,线程模型的选择需要被照顾。

在N-1线程模型,一个单一的内核线程可用来代表每个用户进程的工作。操作系统调度给单个CPU时间片这个内核线程。

在用户空间,程序员请使用POSIX 的pthread 或Windows 的CreateThread()产卵内的多个线程用户进程。由于使用POSIX 的pthread 或Windows程序员的CreateThread()内核知道用户的土地线程,每个线程被认为是由调度处理器时间分配。所以,这意味着每个用户线程会得到一个内核线程。

我的问题:

是这样,那么N-1的线程模型的外观可能存在吗?这将是1-1线程模型。请澄清。


解决方案

  

在用户空间,程序员请使用POSIX的pthread或Windows的CreateThread()到用户的过程中产生多个线程。作为程序员使用POSIX的pthread或Windows的CreateThread()内核知道用户线程的土地,每个线程被认为是由调度处理器时间分配。所以,这意味着每个用户线程会得到一个内核线程。


这是如何1对1的线程的作品。

此不必是这种情况。的平台可以实现在pthread_create 的CreateThread ,或任何其他的创建一个线程功能,它提供了做任何事情,


  

我的问题:


  
  

是这样,那么N-1的线程模型的外观可能存在吗?这将是1-1线程模型。结果
  请澄清。


precisely,你在你的问题的开始阶段 - 当程序员创建一个线程,而不是创建一个线程内核是知道的,它会创建一个线程的用户态调度是知道的,仍然使用单内核线程的整个过程。

In continuation to question, This is an additional query on N-1 threading model.

It is taught that, before designing an application, selection of threading model need to be taken care.

In N-1 threading model, a single kernel thread is available to work on behalf of each user process. OS scheduler gives a single CPU time slice to this kernel thread.

In user space, programmer would use either POSIX pthread or Windows CreateThread() to spawn multiple threads within a user process. As the programmer used POSIX pthread or Windows CreateThread() the kernel is aware of the user-land threads and each thread is considered for processor time assignment by the scheduler. SO, that means every user thread will get a kernel thread.

My question:

So, How does N-1 threading model looks possible to exist? It would be 1-1 threading model. Please clarify.

解决方案

In user space, programmer would use either POSIX pthread or Windows CreateThread() to spawn multiple threads within a user process. As the programmer used POSIX pthread or Windows CreateThread() the kernel is aware of the user-land threads and each thread is considered for processor time assignment by the scheduler. SO, that means every user thread will get a kernel thread.

That's how 1-to-1 threading works.

This doesn't have to be the case. A platform can implement pthread_create, CreateThread, or whatever other "create a thread" function it offers that does whatever it wants.

My question:

So, How does N-1 threading model looks possible to exist? It would be 1-1 threading model.
Please clarify.

Precisely as you explained in the beginning of your question -- when the programmer creates a thread, instead of creating a thread the kernel is aware of, it creates a thread that the userland scheduler is aware of, still using a single kernel thread for the entire process.

这篇关于如何N'LT; - &GT; 1线程模型的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆