Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce concept of blocking extern functions for better interop of GC with foreign code #3116

Conversation

WojciechMazur
Copy link
Contributor

Introduce the concept of blocking extern functions.
Extern functions marked as blocking have special handling in the GC - upon transiting from managed to unmanaged execution (Scala to Native library) information about the current stack top and content of registers is saved to allow for GC.
It is used to skip waiting for potentially blocking threads in the StopTheWorld event, in case the given thread is executing a blocking syscall, eg. waiting for socket connect or reading from a file.
This change allows us to shorten the time spent when synchronizing the threads in case of StopTheWorld event, and does not require us to interrupt threads in order to force they're execution to reach safepoint.

  • Added scala.scalanative.unsafe.blocking annotation
  • Add isBlocking attribute to NIR as field of Attr.Extern
  • Handle @blocking annotation in the compiler plugin
  • Mark potentially blocking functions in libc, posixlib and windowslib

WojciechMazur and others added 9 commits January 29, 2023 15:19
@WojciechMazur WojciechMazur merged commit 9a0569b into scala-native:main Jan 31, 2023
@WojciechMazur WojciechMazur deleted the feature/multithreading-blocking-externs branch January 31, 2023 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant