[D-runtime] A mechanism to kill threads

Steven Schveighoffer schveiguy at yahoo.com
Thu Aug 23 05:28:46 PDT 2012


I realize this thread is very old, but I'm just catching up with my stale email.

Not sure whether anything happened with this, but I would suggest that you simply avoid using D threads whatsoever.  I'd even write the VM in C.  Otherwise, you risk hidden D features that you have no control over that might use the GC.  Like simply using an array literal.

In my experience, it's always been possible (and better) to write a cooperative way to kill a thread.  Then again, I haven't ever written a VM...

-Steve

On May 16, 2012, at 8:55 PM, Alex Rønne Petersen wrote:

> One interesting question in designing a kill function is: Do we want
> to guarantee that it runs all the thread shutdown routines (see the
> shutdown code in thread_entryPoint)? I'm thinking that guaranteeing
> this is basically impossible, so I'm leaning towards no. The most I
> can see would be realistic is to remove the thread from the global
> thread list if enqueueing the termination request (pthread_cancel on
> POSIX, TerminateThread on Windows) succeeded.
> 
> If we don't guarantee this, how much resource leakage are we looking at?
> 
> Regards,
> Alex
> 
> On Wed, May 16, 2012 at 7:04 PM, Alex Rønne Petersen
> <xtzgzorex at gmail.com> wrote:
>> Hi,
>> 
>> In my virtual machine, I need to be able to kill daemon threads on
>> shutdown. The problem is that VM shutdown is *not* tightly coupled to
>> druntime shutdown; multiple VM instances can run in a process at any
>> given time, and can be started/stopped whenever. It doesn't appear
>> like there is any functionality in core.thread to achieve this.
>> 
>> Is there any reason we don't have a Thread.kill() function?
>> 
>> Regards,
>> Alex
> _______________________________________________
> D-runtime mailing list
> D-runtime at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/d-runtime



More information about the D-runtime mailing list