GC and threads
Saaa
empty at needmail.com
Sun Jan 28 12:39:51 PST 2007
As I read it, this is a more general solution than only for ISR routines.
Any realtime thread should be created this way.
Is there any reason not to use this way of creating a thread which writes to
a global variable?
(Where is the C's _beginthread() reference)
Wouldn't it be easier for a GC-safe thread in Phobos?
>
> Interrupt Service Routines
> When the garbage collector does a collection pass, it must pause all
> running threads in order to scan their stacks and register contents for
> references to GC allocated objects. If an ISR (Interrupt Service Routine)
> thread is paused, this can break the program.
>
> Therefore, the ISR thread should not be paused. Threads created with the
> std.thread functions will be paused. But threads created with C's
> _beginthread() or equivalent won't be, the GC won't know they exist.
>
> For this to work successfully:
>
> a.. The ISR thread cannot allocate any memory using the GC. This means
> that the global new cannot be used. Nor can dynamic arrays be resized, nor
> can any elements be added to associative arrays. Any use of the D runtime
> library should be examined for any possibility of allocating GC memory -
> or better yet, the ISR should not call any D runtime library functions at
> all.
> b.. The ISR cannot hold the sole reference to any GC allocated memory,
> otherwise the GC may free the memory while the ISR is still using it. The
> solution is to have one of the paused threads hold a reference to it too,
> or store a reference to it in global data.
>
>
More information about the Digitalmars-d
mailing list