Scheduling concurrency
Have been trying to look at 3 different languages: Go, Kotlin, Elixir/Erlang mostly to understand their concurrency models. This article concerns mostly about Go's preemptive scheduling. Looking at the dense article on go: https://go.googlesource.com/proposal/+/master/design/24543-non-cooperative-preemption.md Here is what I understand. Before Go 1.14: Cooperative preemption at function prologues…
This account explores the three programming languages Go, Kotlin, and Elixir/Erlang, with a focus on their concurrency models. The article delves into Go's preemptive scheduling, particularly in versions 1.14 and beyond.
Prior to Go 1.14, the language utilized cooperative preemption at function prologues. This method allowed the compiler to insert preemption points in those areas, ensuring precise garbage collection by knowing all local GC roots at safe-points. However, this approach had its drawbacks, such as the potential for a program to entirely halt in extreme cases and the introduction of a 7.8% slowdown in large benchmark suites despite efforts to mitigate the issue through fault-based preemption.
Go 1.14 introduced a signal-based non-cooperative preemption mechanism, which enabled switching between concurrent execution contexts without explicit preemption checks or assistance from those contexts. This change mirrors the way modern operating systems manage thread switching. When a goroutine is interrupted, the runtime captures its CPU state and resumes it later, eliminating the need for preemption checks.
The specific choice of the SIGURG signal for this purpose is explained. It meets several criteria, including passing through debuggers by default, not being used internally by libc in mixed Go/C binaries, being spurious and causing no harm, and being unlikely to be used by applications for its intended meaning. SIGUSR, on the other hand, is a different case, representing a more complex intersection of OS signals, compiler internals, runtime, and GC designs.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — it may contain errors, so check the original before relying on it.