I'm currently implementing a compiler for a simple language as a side project in C++. I'd like to add a garbage collector. Most (all?) garbage collection algorithms involve stopping the world at some point.
I'm interested in knowing whether there's an efficient way to temporarily pause a set of threads from the parent thread. The only other option I see is periodically checking if the GC wants to run at the top of every function and loop. This strikes me as inefficient, because I'll have to lock and unlock each time, adding considerable overhead. Is there a more efficient way to do this?