2

I'm studying garbage collectors and it seems like to have a concurrent garbage collector that can handle multiple threads, you'd need to have a lock or atomic refs to restrict garbage collector from changing something at the same moment another thread writes to memory. Do garbage collectors use locks/atomic or am I missing something? I've found references to 'write barriers' but I can't seem to find anything indicating one way or another on this front.

I'm counting a CAS loop as locking.

Thanks!

mczarnek
  • 1,305
  • 2
  • 11
  • 24
  • 1
    Do you know any programming language/ execution environment, where reference assignment is not atomic? – Holger Apr 19 '21 at 08:47
  • 2
    they do and that is indeed done inside the "write barrier". I have tried to explain this (mainly to myself) how that happens in `Shenandoah` [_with_ forwarding pointers](https://stackoverflow.com/questions/59044616/whats-the-mark-compact-algorithm-used-by-hotspot/59141137#59141137) and [_without_ forwarding pointers](https://stackoverflow.com/questions/64002388/shenandoah-2-0-elimination-of-forwarding-pointer). It is rather fascinating how these concurrent GCs work, though very complicated to read the code. – Eugene Apr 19 '21 at 09:56
  • @Holger C++ doesn't require actual atomics to be used for most reference assignments. By atomics I mean operations must be thread synced values, like those found in C++'s atomic library. Thanks Eugene, will read carefully – mczarnek Apr 19 '21 at 15:39
  • 3
    It’s misleading to use C++ semantics for such terms, when asking a question about garbage collection, as C++ has no garbage collection. Nothing in this question hints at C++. – Holger Apr 19 '21 at 15:57
  • It's not just C++, Java and C# and I'm sure others also have similar specific variables. But I went ahead and added C++ as it's what I'm using. – mczarnek Apr 19 '21 at 19:36
  • 1
    Garbage collection in environments that support parallelism is a big research topic. Just look at these papers: https://www.win.tue.nl/~jfg/articles/CSR-04-31.pdf https://link.springer.com/chapter/10.1007/11576235_31 https://docs.oracle.com/en/java/javase/11/gctuning/parallel-collector1.html#GUID-DCDD6E46-0406-41D1-AB49-FB96A50EB9CE – Alexander Voitenko Apr 19 '21 at 20:29

0 Answers0