.NET线程是否不同于操作系统线程? [英] Are .NET threads different from operating system threads?

查看:80
本文介绍了.NET线程是否不同于操作系统线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. .NET线程是轻量级的用户模式线程还是内核模式的操作系统线程?

  2. 还可以节省SQL Server,.NET线程与操作系统线程之间是否存在一对一的对应关系?

我也很感兴趣,因为Thread类具有一对对称的方法,该对方法名为 EndThreadAffinity ,其文档巧妙地表明.NET线程是对实际操作系统线程的轻量级抽象.

此外,我前一段时间在某个堆栈溢出线程本身上读到,Microsoft尝试像SQL Server一样尝试在CLR中保持这种分离.我记得有一个项目正在使用Fiber API来实现此目的,但是我不能说我理解所阅读内容的所有细节.

我想要一些有关此主题的更详细的文献,例如.NET线程的内部结构与Windows创建的线程的内部结构.尽管有很多关于Windows创建的线程结构的信息,但是Jeffrey Richter的 Advanced Windows Programming 书籍就是其中之一,例如,我找不到专门针对内部线程的文献. .NET线程的结构.

有人可能会争辩说,该信息在.NET源代码中可用,现在已经公开可用,或者使用反汇编程序(例如Reflector或IL Spy),但是我看不到任何代表线程控制块(TCB)的信息. ),程序计数器(PC)和堆栈指针(SP)或线程的等待队列,或者该线程当前在Thread类中的成员的队列列表.

我在哪里可以读到?文档中是否有提及?我已经阅读了所有这些来自MSDN的页面,但他们似乎没有提及.

解决方案

.NET的线程确实是抽象的,但是您基本上可以认为它们几乎与OS线程相同.尤其是在垃圾回收方面,存在一些关键差异,但是对于绝大多数程序员(阅读:不太可能启动WinDBG的程序员)来说,它们之间没有功能上的差异.

有关更多详细信息,请阅读此内容

  1. Are .NET threads lightweight user-mode threads or are they kernel-mode operating system threads?

  2. Also, sparing SQL Server, is there a one-to-one correspondence between a .NET thread an an operating system thread?

I am also intrigued because the Thread class that has a symmetric pair of methods named BeginThreadAffinity and EndThreadAffinity, whose documentation subtly suggests that .NET threads are lightweight abstractions over real operating system threads.

Also, I read a while ago on some stack overflow thread itself that Microsoft scratched an attempt to maintain this separation in the CLR, like SQL Server does. There was some project underway to use the Fiber API for this purpose, I recollect, but I can't say I understood all the details of what I read.

I would like some more detailed literature on this topic such as the internal structure of a .NET thread vis-a-vis that of a thread created by Windows. While there is plenty of information available on the structure of a thread created by Windows, Jeffrey Richter's Advanced Windows Programming book being one of the sources, for instance, I can't find any literature dedicated to the internal structure of a .NET thread.

One might argue that this information is available in the .NET source code, which is now publicly available, or using a disassembler such as Reflector or IL Spy, but I don't see anything to represent the Thread Control Block (TCB) and Program Counter (PC) and Stack Pointer (SP) or the thread's wait queue, or the list of queues that the thread is currently a member of in the Thread class.

Where can I read about this? Does the documentation mention any of it? I have read all of these pages from the MSDN but they do not seem to mention it.

解决方案

.NET's threads are indeed abstractions, but you can basically think of them as nearly identical to OS threads. There are some key differences especially with respect to garbage collection, but to the vast majority of programmers (read: programmers who are unlikely to spin up WinDBG) there is no functional difference.

For more detail, read this

这篇关于.NET线程是否不同于操作系统线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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