Tom, see inline...
Willy.
>> Tom,
>>
[quoted text clipped - 16 lines]
> threads, but I don't know if they need to execute on the same physical
> thread each time the logical thread's time-slice phases in.
Logical thread don't execute, only physical threads do, and each logical
thread (an object instance) is associated with a physical thread. This
associating is fixed and exists for the lifetime of the logical thread.
Also logical threads do not get scheduled, so they aren't "time-sliced".
> Actually I don't know the real details about how .NET framework implements
> threading on WinOS. But if the logical thread can be executed by different
[quoted text clipped - 3 lines]
> This is just my train of thought now, considering the difference between
> physical and logical threads.
No, as said before a logical thread is associated with a physical thread
which ceases to exist when the thread procedure exists. Note, I'm not
talking about Threadpool threads, only regular self started threads.
> A sketch of my thoughts
>
[quoted text clipped - 11 lines]
> threads otherwise? Does the documentation say that a logical thread is
> always scheduled on the same physical thread?
Again, a logical thread doesn't get scheduled, it's a CLR data structure not
an active OS object, the CLR keeps track of the asociations and the OS
threads keeps a reference (in TLS) to the corresponding CLR thread's data
structure.
The distinction is simply an abstraction, at the application level you
shouldn't care about the underlying implementation, that way the CLI
implementor has the freedom to implement threading as he sees fit (depending
on the available OS platform services). For instance the CLI (or an Hosting
process like SQL2005) could associate a Fiber instead of a OS thread to a
logical thread.
In such a case, multiple logical threads would run on the same OS thread,
and these logical threads would end on the same CPU if you set the OS thread
affinity.
Willy.
chuckb@empiricdesign.com - 16 Dec 2005 18:50 GMT
I can think of a couple of reasons you might/may want to set processor
affinity (even from managed code).
1. You're selling an application that you license by the processor.
They've only bought a one-processor license, so that's all they get.
2. You are USING an application that you license by the processor (SQL
Server) and you're not using all the processors for it. You might want
to have your application running on the non-SQL Server processors so
that it doesn't slow down the SQL Server ones. Memory would be a
separate issue, of course.
Chuck
Willy Denoyette [MVP] - 17 Dec 2005 15:40 GMT
>I can think of a couple of reasons you might/may want to set processor
> affinity (even from managed code).
>
> 1. You're selling an application that you license by the processor.
> They've only bought a one-processor license, so that's all they get.
HT cores are not physical CPU's! You ain't gonna license your application
per logical CPU do you?
> 2. You are USING an application that you license by the processor (SQL
> Server) and you're not using all the processors for it. You might want
> to have your application running on the non-SQL Server processors so
> that it doesn't slow down the SQL Server ones. Memory would be a
> separate issue, of course.
Same here SQL server license is not per logical CPU, an HT P4 for instance
is considered one single CPU for SQL server (and for the Windows OS).
Willy.