If done correctly, there shouldn't be a problem. You are right that you
might not always have physical thread affinity (SQL Server is an example of
this), but that's not something that you should be worried about while
programming with the CLR (at least since .NET 2.0, when the distinction
between logical thread and physical thread was firmly established).
Assuming that the host is correctly programmed, things such as TLS and
whatnot should work accordingly.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Well, Truth be told, I always wonder about this. For the Original Poster -
> don't worry, you're fine -- we're way in the real of useless arcana at
[quoted text clipped - 24 lines]
>>>
>>> Thanks!
On Sep 10, 3:06 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.com> wrote:
> Assuming that the host is correctly programmed, things such as TLS and
> whatnot should work accordingly.
I don't think the same can be said of unmanaged APIs that require
thread affinity though. Fortunately, I don't there are very many of
those out there.
Nicholas Paldino [.NET/C# MVP] - 10 Sep 2007 22:15 GMT
Brian,
Absolutely, but if you are using unmanaged APIs, it's already well-known
that you are forfeiting the benefits of the CLR for the duration of that
call.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> On Sep 10, 3:06 pm, "Nicholas Paldino [.NET/C# MVP]"
> <m...@spam.guard.caspershouse.com> wrote:
[quoted text clipped - 5 lines]
> thread affinity though. Fortunately, I don't there are very many of
> those out there.
That whole "if done correctly" though, is quite a can of worms.
For example, I do alot of LDAP & AD, through System.DirectoryServices. These
classes appear (through emperical evidence) to have native thread affinity.
I don't see how I could use UnManaged API calls, many of which do have
thread Affinity, if I'm unsure of the physical thread that I'm on. For
certain, as long as stay "Inside the VM", the CLR will protect me. For
things like TLS, this is guaranteed (I even checked with Duffy about this,
some time ago).
... but the sad reality is that .Net code ends up calling into native code,
and an awful lot of native code has physical thread affinity. This is often
true cases where it would not be at all obvious (c.f.,
System.DirectoryServices). The day logical and physical threads start
actually being seperate, I think alot of unexpected things are going to
break.
I've heard a number of people say SQL Server does this already, but I don't
think it's the case. For sure, there was a huge effort in .Net 2.0 to get
Fibers working right for the SQL Guys, but (again, according to Duffy) this
was abandoned at the 9th hour, and offically, "Not Supported"
(http://www.bluebytesoftware.com/blog/PermaLink,guid,2d0038b5-7ba5-421f-860b-d928
2a1211d3.aspx).
Is there any evidence that SQL Server does actually swap logical threads
across physical threads?

Signature
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP
http://www.coversant.com/blogs/cmullins
> If done correctly, there shouldn't be a problem. You are right that
> you might not always have physical thread affinity (SQL Server is an
[quoted text clipped - 34 lines]
>>>>
>>>> Thanks!
Willy Denoyette [MVP] - 11 Sep 2007 13:46 GMT
> That whole "if done correctly" though, is quite a can of worms.
>
> For example, I do alot of LDAP & AD, through System.DirectoryServices.
System.DirectoryServices are wrappers around ADSI, which is a COM based, as
such the affinity is due to the COM apartment requirements. But actually
this is taken care of by System.DirectoryServices itself, if the caller is
not running in an MTA thread, System.DirectoryServices will create his own
thread enter the MTA end keep this thread around for the life time of the
instance.
Note that the lower level managed LDAP libraries
(System.DirectoryServices.Protocols and
System.DirectoryServices.ActiveDirectory )do not have such affinity, nor do
they have any relation with the COM ADSI stuff), therefore you should prefer
to use these when you have to deal with LDAP connections.
These
> classes appear (through emperical evidence) to have native thread
> affinity. I don't see how I could use UnManaged API calls, many of which
[quoted text clipped - 18 lines]
> Is there any evidence that SQL Server does actually swap logical threads
> across physical threads?
Sure it does, the SQL server host manages his own threading and fibers
stuff, he doesn't use the CLR threads (nor it's ThreadPool).
The SQL team is the only team that knows what fibers are all about, after a
failed attempt to integrate this in the CLR, they decided to handle
threading themselves and gave up about the CLR for this. IMO we won't ever
see fibers supported in the CLR.
There are a couple of other CLR services that aren't used by SQLCLR, these
guys are hunting for 99.9999% availability, something that can't be
guaranteed by the CLR.
Willy.