Is Thread a Kernel Object?

In this book, I read that each instance of the Thread class actually allocates a kernel object - and this is one of the overhead of using Thread .

As far as I know, a thread is not a kernel object (only a process is a kernel object in this case. Is the thread that contains this process not a kernel object?)

Can someone explain?

+2
c # clr
Feb 17 '12 at 13:50
source share
2 answers

At first, a thread is a managed object, you know the System.Threading.Thread class. Now this is an internal CLR object, the C ++ class is also called Thread. There, rather, a huge amount of plumbing is connected with an iceberg. This plumbing certainly uses kernel objects, five of them. Something you can see in Taskmgr.exe . One of them is its own handle to the operating system thread, the other four are a little mysterious, but they are probably handlers of synchronization objects.

Decoupling Thread with real Windows thread objects in .NET 2.0 is pretty sad. This is only technically possible, none of the famous people have ever implemented the CLR host, which made it work. This was an important project for the SQL Server team to implement Thread with fibers, and they abandoned it. Failed to make it reliable enough. Since then I don’t know.

+3
Feb 17 2018-12-17T00:
source share

From MSDN about Thread instances:

The ThreadId operating system does not have a fixed connection with a managed thread, because an unmanaged host can control the relationship between managed and unmanaged threads. In particular, a complex host can use the CLR Hosting API to schedule many managed threads against the same operating system thread or to move a managed thread between different operating system threads.

There are other kinds of threads or thread-like things in .NET. There is a thread from ThreadPool, and there are Tasks. None of the AFAIKs are directly related to OS threads.

In general, I understand that no, .NET threads do not necessarily contain kernel objects.

+2
Feb 17 '12 at 13:59
source share



All Articles