Scala Native Thread & GC issues

265 views Asked by At

Currently ScalaNative is single threaded. But we can used POSIX API (for example) to create and manage threads (ans also shared resources).

My questions are related to the garbage collector:

  • is it safe to use scala native and its default GC (immix) with threads ?
  • if the answer is yes. This solution may be not as efficient as expected; is there some benchmarks ?
  • if the answer is no. Is it clever to change the GC to Boehm which is claimed to be concurrent ?
1

There are 1 answers

0
Andreas ZUERCHER On
  • No, it is not currently (Scala Native Release 0.4.0 on 19 January 2021) safe to use Scala Native with immix as GC in anything other than strictly single-threaded. The comment https://github.com/scala-native/scala-native/issues/101#issuecomment-633495602 discusses some of the then-current(-as-of-25-May-2020) experimentation into multithreaded immix and impact of green threads on GC.
  • Although Boehm GC per se might be capable of supporting multithreaded GC, it depends on the rest of the language's runtime & memory model properly interacting with the multithreaded-GC rules within the Boehm garbage collector, which Scala Native currently does not do regarding, e.g., “safe points”.
  • As I understand it, crude usage of multithreaded Scala Native has been to have a GC per thread and keep all of that thread's allocations accessible only on that thread so that there is never any inter-thread access of any instance, so that each thread is in isolation as if it is single-threaded for all that that thread can see. But this spartan crude strict quarantining of each thread is not what is normally meant by a multithreaded app.