Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2005

Tip: Looking for answers? Try searching our database.

.NET Threading (& Windows threading)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew - 25 Aug 2005 19:24 GMT
I'd like to know how the CLR handles threading... I think the call to the
OS's Win32 method CreateThread() in C or C++ creates an operating system
thread with its own stack.   But what does .NET do?  Are managed threads
assigned an OS stack?  

Also, I'm kind of amateurish with this stuff... so if there are some general
good threading resources (Windows and .NET) on the internet you could point
me to them?

Thanks

-Andrew
Mattias Sjögren - 25 Aug 2005 20:16 GMT
>But what does .NET do?  Are managed threads
>assigned an OS stack?  

In v1.x the answer is yes, there's a 1:1 mapping between managed and
native threads.

v2.0 is a bit more flexible and gives a runtime host more control over
this, making it possible to use fibers instead.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Michael D. Ober - 26 Aug 2005 14:27 GMT
Fibers, which are lightweight threads, are also natively supported on
Windows 2000 and later.  The answer would still be "yes", there's a 1 to 1
mapping between .NET threads and OS threads.

Mike Ober.

> >But what does .NET do?  Are managed threads
> >assigned an OS stack?
[quoted text clipped - 6 lines]
>
> Mattias
Andrew - 26 Aug 2005 15:10 GMT
Thanks!

> Fibers, which are lightweight threads, are also natively supported on
> Windows 2000 and later.  The answer would still be "yes", there's a 1 to 1
[quoted text clipped - 12 lines]
> >
> > Mattias
Willy Denoyette [MVP] - 26 Aug 2005 16:20 GMT
> Fibers, which are lightweight threads, are also natively supported on
> Windows 2000 and later.  The answer would still be "yes", there's a 1 to 1
> mapping between .NET threads and OS threads.
>
> Mike Ober.

No there is not, you can have multiple logical threads assigned to the same
OS thread when they are mapped to fibers.

Willy.
Michael D. Ober - 26 Aug 2005 18:16 GMT
So can the OS.  A fiber is, at it's simplest, a thread that the OS can't
schedule.  As such, it must have a parent thread that schedules it.  Windows
allows multiple fibers to have the same parent thread.  Thus, a .Net mapping
of a thread still maps to a single OS thread.  A .Net mapping of a fiber
maps to a single OS fiber.

From MSDN:

"A fiber is a unit of execution that must be manually scheduled by the
application. Fibers run in the context of the threads that schedule them.
Each thread can schedule multiple fibers. In general, fibers do not provide
advantages over a well-designed multithreaded application. However, using
fibers can make it easier to port applications that were designed to
schedule their own threads."

=======
Ada does it's own thread scheduling, which is partly why the US DoD wanted
(note the past tense) to use Ada for weapons systems.

For what it's worth, there is a warning in the Beta 2 MSDN to not treat
pooled threads as OS threads.  From reading this warning, it appears that
the managed thread pool actualy is a pool of OS fibers.
<http://msdn2.microsoft.com/library/ms182291(en-us,vs.80).aspx >

Mike.

> > Fibers, which are lightweight threads, are also natively supported on
> > Windows 2000 and later.  The answer would still be "yes", there's a 1 to 1
[quoted text clipped - 6 lines]
>
> Willy.
Willy Denoyette [MVP] - 26 Aug 2005 20:01 GMT
As you stated correctly an OS thread can host multiple fibers, that means
that the managed threads A and  B can be mapped on the same OS thread
through 2 different fibers, this is not what I would call a one to one
mapping but a many to one mapping.
The managed thread pool in v2.0 thread is NOT based on fibers, what's more,
the CLR doesn't know anything about fibers, they come into play when the CLR
is hosted, and it's the unmanaged host that must provide/manage the
threadpool based on fibers (a number of threads each hosting a number of
fibers).
That's exactly what SQL2005 does when hosting the CLR, it provides the
fibers based threadpool, the CLR doesn't use it's own implementation and
simply posts it's "workitems" to the host provided threadpool. This is what
the msdn2 page talks about.

Willy.

> So can the OS.  A fiber is, at it's simplest, a thread that the OS can't
> schedule.  As such, it must have a parent thread that schedules it.
[quoted text clipped - 38 lines]
>>
>> Willy.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.