all groups > dotnet clr > march 2007 >
You're in the

dotnet clr

group:

System.Threading.Thread



System.Threading.Thread Amelyan
3/23/2007 1:05:49 PM
dotnet clr: 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,

Re: System.Threading.Thread Barry Kelly
3/23/2007 5:57:47 PM
[quoted text, click to view]

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

[quoted text, click to view]

-- Barry

--
Re: System.Threading.Thread Amelyan
3/26/2007 2:24:30 PM
In other words, if don't stop my thread explicitly, it will run
indefinitely, even if no references are pointing at this Thread object.


[quoted text, click to view]

Re: System.Threading.Thread Jon Skeet [C# MVP]
3/26/2007 7:44:49 PM
[quoted text, click to view]

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 - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
Re: System.Threading.Thread Amelyan
3/28/2007 1:04:54 PM
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?


[quoted text, click to view]

Re: System.Threading.Thread Jon Skeet [C# MVP]
3/28/2007 7:40:35 PM
[quoted text, click to view]

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

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
Re: System.Threading.Thread Willy Denoyette [MVP]
3/29/2007 1:09:10 AM
[quoted text, click to view]

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.


Re: System.Threading.Thread Patrick van Dijk
3/29/2007 1:19:53 AM
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/


[quoted text, click to view]

Re: System.Threading.Thread bazad
4/1/2007 11:32:36 PM
Are you talking about native threads or .NET threads?

What are these rare occasions?

[quoted text, click to view]
Re: System.Threading.Thread Willy Denoyette [MVP]
4/2/2007 1:25:27 PM
[quoted text, click to view]
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".


[quoted text, click to view]
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.
Re: System.Threading.Thread Ben Voigt
4/2/2007 2:09:39 PM

[quoted text, click to view]

It is a bad driver design, which was finally fixed in Vista (see discussions
of CancelIoEx).

Re: System.Threading.Thread Ben Voigt
4/2/2007 2:11:18 PM

[quoted text, click to view]

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.

Re: System.Threading.Thread Günter Prossliner
4/2/2007 6:38:12 PM
Hi Willy!

[quoted text, click to view]

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

Re: System.Threading.Thread Willy Denoyette [MVP]
4/2/2007 10:40:41 PM
[quoted text, click to view]

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.


Re: System.Threading.Thread Willy Denoyette [MVP]
4/2/2007 11:14:27 PM
[quoted text, click to view]

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.

AddThis Social Bookmark Button