3 ms·
In fact, most garbage collection variants are very pleasant to implement if you assume that your system only has one type of object. (Simple enough to ask under
by ezyang 11y ago
In fact, most garbage collection variants are very pleasant to implement if you assume that your system only has one type of object. (Simple enough to ask undergraduates to do as a weekly homework.) Things get more hairy when you (1) want to support multiple objects, and (2) want to make it fast.
- kazinator 11y agoSupport for multiple objects and making it fast is dwarfed by ... requirement for threads (not those green ones). Now all those regions of code where "we can muck with this object before returning it because we know GC isn't running, because we don't call any allocation functions that can trigger GC" have to be locked down. (Among other problems to solve, like that a thread can be doing anything when you pause it.)
- Manishearth 11y agoInterestingly, for rust-gc, the initial safe GC design was the hard part. Concurrency is easy to bolt on to it[1]. Basically, once we had a GC design that was "safe" (In Rust terms; i.e. can't be used in safe Rust to trigger memory or thread unsafety), making GCd objects passable between threads was a clean, logical extension of the existing model. This is probably because Rust's safety model in a single threaded situation is very close to what you need for multithreaded safety too. [1]: however it gets tricky again if you want to avoid pausing threads as much as possible (i.e. only pause on a GC mutation).