Hello, I'm writing a semi-accurate garbage collector, and I'm wondering if there is a way to accurately detect the boundaries of the system-allocated stack for a given thread.
I need this so I can scan the stack for roots (pointers), and my current approach is to save the stack pointer when entering a new thread and when entering main(), and then to save it again for each thread when starting a garbage collection, using a global lock.
(I know that this approach is not ideal in the long run, since it causes unnecessary locking, but for now it is acceptable until the basics are up)
But I would really like to have a more "secure" way of detecting the boundaries, because it is quite easy for roots to 'escape' this mechanism (depending on the thread implementation -- pthreads is easy to manage, but not so with OpenMP or Grand Central Dispatch).
It would be even more awesome if there was a portable way to do this, but I don't expect that to be the case. I'm currently working on Mac OS X 10.6, but answers for any platform are welcome.