Groups | Blog | Home
all groups > dotnet clr > december 2003 >

dotnet clr : Real-time threads and GC


Steve Terepin
12/30/2003 2:39:48 PM
I'm writing an app that does real time data acquisition, and needs to
respond to DMA-complete events that get signalled every 10mS approximately.
Currently I have some native C++ code that works very nicely, with a
dedicated 'daemon' thread that waits on a Win32 Event and kicks off the next
DMA transfer as soon as the previous one has completed. Now I'd like to
rework this as a Managed C++ component that I can invoke from C#, but I'm
wary of the fact that in a .Net app, the garbage collector can in principle
kick in at any time and suspend all threads whilst it does its work. What
would I need to do to ensure that my 'daemon' thread continues to be alive
all the time, and can respond immediately when the Event it's waiting on
gets signalled ? If that thread were to be suspended due to GC, it wouldn't
get a chance to kick off the next DMA transfer and I'd probably suffer a
data overrun. My hope is that if I just create the thread in the usual way
with _beginthreadex, and just keep it spinning in a loop monitoring the
Win32 Event, there would be no reason for the GC to take an interest in that
thread and suspend it ; but on the other hand, maybe the GC plays safe and
suspends *all* threads in the application ?

Steve.

Hiroaki SHIBUKI
1/12/2004 1:16:14 AM
Hi,

[quoted text, click to view]

Yes. I think so. it can become a problem.

[quoted text, click to view]

I guess that GC will *not* suspends all threads, I think that GC'll be care
of managed threads only.

But its just a my guess, it have to be verifiied by experiment.

--
Hiroaki SHIBUKI


[quoted text, click to view]
Simon Hall [MSFT]
1/12/2004 11:45:20 AM
Steve,

The collector will only suspend threads that are
currently executing managed code, and those that try to
execute managed code during a collection. Threads running
outside of the CLR will be left alone.

Cheers,
Simon

[quoted text, click to view]
AddThis Social Bookmark Button