How to get the CLR to display OS thread switching?

In connection with these issues:

How to get the _real_ thread id in the CLR and the "friendly" way?

How often does thread-controlled OS thread switching occur?

I would like to be able to actually test the Thread.BeginThreadAffinity () methods and check how they work and that they work.

Is there some kind of .NET function that will force the OS thread switch?

-one
c # clr pinvoke
Mar 14 '13 at 10:02
source share
1 answer

There is not much to test with Thread.BeginThreadAffinity (). I call the function on the CLR host, IHostTaskManager :: BeginThreadAffinity () . IHostTaskManager is an additional interface that the CLR user host can implement to provide a user thread that does not necessarily use the operating system thread. The ICLRTaskManager and ICLRTask interfaces provide basic services for such a custom thread.

These interfaces were added to .NET 2.0 at the request of the SQL Server team. SQL Server has a custom threading option built in over time based on fiber. Fibers were popular in earlier times when machines with multiple processor cores were still rare. Other fiber names are "green thread" and "joint procedure." They were pastured due to the multi-core revolution in the previous decade.

The SQL Server project was a bust. They could not get it reliable enough and abandoned the project. Unfortunately, we are left with the consequences, there is no easy way to map the .NET thread to the OS thread, the subject of your first link. Like the significant FUD shown in the accepted answer.

While the CLR still supports basic support for this feature, I don't know a single example where a user host implements its own threading. The massive abandonment of the SQL Server team project was certainly the main pointer, which is difficult to implement, given the resources the team had access to do this job. And it just doesn’t make sense at all, matching one thread with one processor core, as the operating system does by default and is used by the default CLR host, is incredibly difficult to beat to increase efficiency. CPU cores are very cheap to buy these days.

In short: Thread.BeginThreadAffinity () does nothing . CLR threads are already tied to OS threads by default. The chances that you will ever run the CLR user host, where it does something at all, are close enough to zero to ignore the method.

An easy way to invoke the OS thread context switch is to use one of the WaitHandle.WaitXxx () or Thread.Sleep () methods with unnecessary waiting.

+3
Mar 14 '13 at 12:33
source share



All Articles