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 / CLR / April 2007

Tip: Looking for answers? Try searching our database.

System.Threading.Thread

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Amelyan - 23 Mar 2007 18:05 GMT
When System.Threading.Thread object gets destroyed by GC, does GC
automatically  Abort this thread if IsAlive is true, i.e. thread is still
running?

Thanks,
Barry Kelly - 23 Mar 2007 18:57 GMT
> When System.Threading.Thread object gets destroyed by GC,

GC doesn't collect Thread objects which are still running.

> does GC
> automatically  Abort this thread if IsAlive is true, i.e. thread is still
> running?

-- Barry

Signature

http://barrkel.blogspot.com/

Amelyan - 26 Mar 2007 19:24 GMT
In other words, if don't stop my thread explicitly, it will run
indefinitely, even if no references are pointing at this Thread object.

>> When System.Threading.Thread object gets destroyed by GC,
>
[quoted text clipped - 5 lines]
>
> -- Barry
Jon Skeet [C# MVP] - 26 Mar 2007 19:44 GMT
> In other words, if don't stop my thread explicitly, it will run
> indefinitely, even if no references are pointing at this Thread object.

Absolutely. If it didn't do this, you'd have to make sure you always
had a reference to all "child" thread objects, which would often be a
real pain.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Amelyan - 28 Mar 2007 18:04 GMT
What about when the process that created the thread dies, will thread keep
running indefinitely?  If so, I would need to restart my machine just to
kill this thread?

>> In other words, if don't stop my thread explicitly, it will run
>> indefinitely, even if no references are pointing at this Thread object.
>
> Absolutely. If it didn't do this, you'd have to make sure you always
> had a reference to all "child" thread objects, which would often be a
> real pain.
Jon Skeet [C# MVP] - 28 Mar 2007 19:40 GMT
> What about when the process that created the thread dies, will thread keep
> running indefinitely?  If so, I would need to restart my machine just to
> kill this thread?

The thread is part of the process - if the process dies, the thread
will have died too.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Willy Denoyette [MVP] - 29 Mar 2007 00:09 GMT
> What about when the process that created the thread dies, will thread keep running
> indefinitely?  If so, I would need to restart my machine just to kill this thread?

The process is removed after all of it's threads are removed, when the OS can't remove a
thread from a process (there are rare occasions in which this can happen), then the process
will not die.

Willy.
bazad - 02 Apr 2007 07:32 GMT
Are you talking about native threads or .NET threads?

What are these rare occasions?

> The process is removed after all of it's threads are removed, when the OS
> can't remove a thread from a process (there are rare occasions in which
> this can happen), then the process will not die.
Willy Denoyette [MVP] - 02 Apr 2007 12:25 GMT
> Are you talking about native threads or .NET threads?

Hmmm what are .NET threads?
Framework Threads are mapped to OS threads, the active component in a process is an OS
thread, the OS doesn't know anything about what you call ".NET threads".

> What are these rare occasions?

The rare occasions are when threads actually ignore the request to abort when they actually
execute kernel code (say - buggy driver code). Such threads can't be cleaned-up and as
result the process stays in the process table, they go away only at system reboot.

Willy.
Günter Prossliner - 02 Apr 2007 17:38 GMT
Hi Willy!

> The rare occasions are when threads actually ignore the request to
> abort when they actually execute kernel code

While this is absolutly true...

(say - buggy driver code)

... the word "buggy" may be misleading here. Try to abort a thread (even
with the unmanged "TerminateThread" API), which is waiting for some data
from a Socket (sync operation). No chance, but I won't call the code buggy.

GP
Ben Voigt - 02 Apr 2007 20:09 GMT
> Hi Willy!
>
[quoted text clipped - 9 lines]
> from a Socket (sync operation). No chance, but I won't call the code
> buggy.

It is a bad driver design, which was finally fixed in Vista (see discussions
of CancelIoEx).
Willy Denoyette [MVP] - 02 Apr 2007 22:14 GMT
> Hi Willy!
>
[quoted text clipped - 10 lines]
>
> GP

Don't know what OS version you have this on, but I can't remember having a socked (Winsock)
blocked waiting for IO completion to be not honoring the abort on NT4 and higher.

Willy.
Ben Voigt - 02 Apr 2007 20:11 GMT
>> Are you talking about native threads or .NET threads?
>>
> Hmmm what are .NET threads?
> Framework Threads are mapped to OS threads, the active component in a
> process is an OS thread, the OS doesn't know anything about what you call
> ".NET threads".

In the current runtime, yes.  But .NET makes no guarantee that .NET threads
(or Framework threads as you call them, or managed threads, or etc) map to
OS thread, only that .NET threads act like thread of execution and that .NET
ThreadLocalAttribute applies to .NET threads.
Willy Denoyette [MVP] - 02 Apr 2007 21:40 GMT
>>> Are you talking about native threads or .NET threads?
>>>
[quoted text clipped - 6 lines]
> threads act like thread of execution and that .NET ThreadLocalAttribute applies to .NET
> threads.

Right, but you are referring to the (un-finished/failed)  attempt of the CLR team to
introduce fibers in the CLR, unfortunately support for fibers was cancelled, and AFIAK there
are no plans to introduce them anytime soon. The SQL team was the one that requested this
feature, but finally they gave up waiting and they implemented this in the SQL unmanaged
hosting code.
Anyway, even when fibers (which run in the context of a thread), ever gets stuck in a "badly
behaving kernel component", then it's thread won't die either when ordered to abort.
I prefer not to talk .NET, this is a marketing term that covers nothing we are discussing
here, I prefer to talk about the CLR and/or the Framework, that's why I asked what was meant
with .NET threads, such things don't exist, really.

Willy.
Patrick  van Dijk - 29 Mar 2007 09:19 GMT
I believe you will have to set
  IsBackground = true
then in .NET when the main process thread dies, it will cleanup the
threads marked as background.

Patrick van Dijk
http://www.spatial-eye.com/

> What about when the process that created the thread dies, will thread keep
> running indefinitely?  If so, I would need to restart my machine just to
[quoted text clipped - 11 lines]
> >http://www.pobox.com/~skeet  Blog:http://www.msmvps.com/jon.skeet
> > If replying to the group, please do not mail me too

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.