Forum Navigation
GC and system callbacks
Posted: 03/18/10 23:23:40Hi!
I'm hunting one of those nice heisenbugs in my audio player ... and I'm out of ideas. So I thought I'll ask here if someone can give me some tips or new ideas as to what I could do.
So: I have the GC and I have an audio callback function (ASIO/Windows in this case). Sooner or later I get an access violation when those two things come in contact.
Theoretically this shouldn't happen. My callback function doesn't touch memory handling at all, it neither creates nor destroys memory. But as soon as another thread in the background is busy the access violations occur. If I substitute my ASIO code with a dummy (a class based on a Windows timer that behaves like a real audio interface) it works flawlessly, even with GC. If I disable the GC it works flawlessly too. If I just have the callback running and disable the rest of the program (the background threads which decode audio files) it works too. But as soon as I open an ASIO driver, have GC enabled and have some audio data pushed through the system it crashes after some time (the higher the system load the more likely it crashes, so it crashes most likely when the program is still initializing or opening new files for example).
So I'm guessing it's the GC that kicks in in one thread, while the system is busy in the audio callback. I have no idea why that can crash, but it's my best guess. I have no idea how the GC actually works, so that's basically why I'm asking here. If one of you who has some insight into the inner workings with respect to callbacks and multithreading it would be great if you could help me out here. It's really very frustrating now; I'm hunting this bug for over two days now and I can't think of anything ... so ... any help would be appreciated.
Regards, Mike