4

I know I should not rely upon that there is one-to-one mapping between managed and unmanaged threads. From MSDN:

An operating-system ThreadId has no fixed relationship to a managed thread, because an unmanaged host can control the relationship between managed and unmanaged threads. Specifically, a sophisticated host can use the Fiber API to schedule many managed threads against the same operating system thread, or to move a managed thread among different operating system threads.

In real life though, do such CLR hosts exist? (and if so, what are they?) I just answered a related question, and I wonder how practically bad my advice was for that particular case.

Community
  • 1
  • 1
noseratio
  • 59,932
  • 34
  • 208
  • 486

1 Answers1

5

One would or could have been Microsoft SQL Server (starting with version 2005). IIRC that particular hosting support was even built into the CLR 2.0 upon their request (also see this blog post for more background), so that they could also support the CLR when using fibers (aka user mode scheduling) instead of threads in SQL Server.

However, that never really did work, it seems (source):

Common language runtime (CLR) execution is not supported under lightweight pooling. Disable one of two options: "clr enabled" or "lightweight pooling.

I would consider it rather safe to assume that there are no (production ready) hosts out there, that don't map CLR threads to host threads 1:1.

There are a couple of Q&A around SO that seem to suggest the same.

For example,

Community
  • 1
  • 1
Christian.K
  • 47,778
  • 10
  • 99
  • 143
  • Thanks @Christian.K, I think this is the answer, I've come to the same conclusion. I'd just let the question hang on for a little longer. – noseratio Aug 26 '13 at 11:14
  • 2
    I cannot think of any either. Even the [Singularity OS](http://research.microsoft.com/pubs/52716/tr-2005-135.pdf) appears to have 1:1 mapping. Though I suppose future hypothetical sandboxing OSes might deviate from this. Allowing nonnative thread mapping in the CLR is probably a good idea even if it isn't fully utilized yet. – Brian Gideon Aug 26 '13 at 16:26
  • 1
    You remember correctly; and fiber support went as far as Beta 2. I think it's a pity they dropped it (http://joeduffyblog.com/2006/11/09/fibers-and-the-clr/). I suspected briefly that the CLR in WP8.1 (for Phone Store Apps) could have run on fibers, but it seems unlikely. – Lorenzo Dematté Jan 26 '15 at 16:25