Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does each managed thread have its own corresponding native thread?

I want to know if creating a managed thread in .Net (by calling Thread.Start()) causes that exactly one native thread to be created in background? So is there a corresponding native thread for a managed threads? If yes, when a managed thread waits or sleeps, does it mean that the corresponding native thread also waits or sleeps?

like image 636
Mohammad Ali Bozorgzadeh Avatar asked Oct 20 '13 11:10

Mohammad Ali Bozorgzadeh


People also ask

Does each thread have its own stack?

It is important to distinguish between these two types of process memory because each thread will have its own stack, but all the threads in a process will share the heap. Threads are sometimes called lightweight processes because they have their own stack but can access shared data.

Does each thread within a process has its own program counter and stack space?

Threads are not independent of one another like processes are, and as a result threads share with other threads their code section, data section, and OS resources (like open files and signals). But, like process, a thread has its own program counter (PC), register set, and stack space.

Do multiple threads share the same stack?

Yes , in multithreading each thread has its own stack. having a separate stack is what makes thread's independent of each other.

What is a managed thread?

A manageable version of a ThreadFactory . A ManagedThreadFactory extends the Java™ SE ThreadFactory to provide a method for creating threads for execution in a Java™ EE environment.


1 Answers

Yes, a .NET Thread maps to a native operating system thread on all current CLR hosts.

There's an option to map it to something else in the hosting api through the ICLRTaskManager interface, like a fiber, but that is not actually implemented in any of the main-stream hosts. The SQL Server team at the .NET 2.0 time frame attempted this but the project was abandoned when they could not make it reliable enough. This was not tried again. Technically you could run into a custom hosted CLR, started by an unmanaged program, that implemented this mapping but the odds are rather low.

like image 139
Hans Passant Avatar answered Oct 03 '22 21:10

Hans Passant