HighTechTalks DotNet Forums  

managed/native thread affinity

Dotnet Framework (CLR) microsoft.public.dotnet.framework.clr


Discuss managed/native thread affinity in the Dotnet Framework (CLR) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
zhangrusi
 
Posts: n/a

Default managed/native thread affinity - 08-01-2006 , 04:19 PM






Hi,

I have two questions about managed/native thread affinity in applications
hosted by ASP.NET, running under version 2.0 of the .NET Framework:

1) Is it ever possible for two or more managed threads to be multiplexed
onto the same native thread?

2) Is it ever possible for a managed thread to be switched from one native
thread to another during its lifetime?

Are either of these scenarios possible in future version of the ASP.NET or
the Framework?

I am asking because I have an ASP.NET application that calls into a Java
virtual machine through the Java Native Interface (JNI). JNI (actually the
JVM) can maintain state across calls, and this state is
native-thread-specific. To use JNI on a given thread, I must first call an
API method to "attach" the thread to the JVM. Here two things happen:
- The JVM creates a Java thread that is mapped to the native thread on which
the call was made.
- I get back a handle to use for making future JNI calls. This handle is
specific to the calling native thread.
Instability will result if native thread A attempts to make JNI calls using
native thread B's handle (scenario 1 above), or if two separate "logical"
threads of execution attempt to make calls using the same handle (scenario 2).

I am hoping to gain more insight into the current and future "rules" for
managed/native thread affinity in the CLR.

Thanks a lot.

Reply With Quote
  #2  
Old   
Willy Denoyette [MVP]
 
Posts: n/a

Default Re: managed/native thread affinity - 08-19-2006 , 06:24 AM






Inline...

"zhangrusi" <zhangrusi (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hi,

I have two questions about managed/native thread affinity in applications
hosted by ASP.NET, running under version 2.0 of the .NET Framework:

1) Is it ever possible for two or more managed threads to be multiplexed
onto the same native thread?

Not unless you call SQLCLR managed functions (SQL2005 hosted
applications/stored procs/functios).

Quote:
2) Is it ever possible for a managed thread to be switched from one native
thread to another during its lifetime?

Not, with the current versions of the CLR, anyway in V2 it's possible to
affinitize the thread through the native hosting API's (search MSDN for
details).

Quote:
Are either of these scenarios possible in future version of the ASP.NET or
the Framework?

Only MSFT can tell.

Quote:
I am asking because I have an ASP.NET application that calls into a Java
virtual machine through the Java Native Interface (JNI). JNI (actually
the
JVM) can maintain state across calls, and this state is
native-thread-specific. To use JNI on a given thread, I must first call
an
API method to "attach" the thread to the JVM. Here two things happen:
- The JVM creates a Java thread that is mapped to the native thread on
which
the call was made.
- I get back a handle to use for making future JNI calls. This handle is
specific to the calling native thread.
Instability will result if native thread A attempts to make JNI calls
using
native thread B's handle (scenario 1 above), or if two separate "logical"
threads of execution attempt to make calls using the same handle (scenario
2).

I am hoping to gain more insight into the current and future "rules" for
managed/native thread affinity in the CLR.

You should never assume such a mapping or affinity rule, some hosts (like
SQL2005) can allready map logical threads to fibers and fibers can migrate
from one native thread to another.

Willy.




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.