Randeep Singh
Randeep Singh

Reputation: 1275

When we create and start a new .NET thread, does it create a new OS level thread?

When we create a new thread in this way:

Threading.Thread t = new Threading.Thread(() => { Console.WriteLine("My New thread"); });
t.Start();

Is it going to create an OS level thread as well?

Upvotes: 7

Views: 139

Answers (1)

Hans Passant
Hans Passant

Reputation: 941485

Technically this is undefined, a custom CLR host can use any construct to implement a thread. The underlying hosting interface is IClrTask. Nor is there a decent way to find out.

Practically this never happens. IClrTask was added at the request of the SQL Server group which wanted the option to map a thread onto a fiber. That project ultimately failed, they could not get it stable enough. A red flag to anybody that might have had similar plans. Unless you are acting as a plugin to a large unmanaged program similar to SQL Server, you can always assume you'll consume an OS thread.

Upvotes: 12

Related Questions