-
Notifications
You must be signed in to change notification settings - Fork 909
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
WIP: threading support #4559
base: dev
Are you sure you want to change the base?
WIP: threading support #4559
Commits on Oct 29, 2024
-
internal/task: add non-atomic atomic operations
This adds some non-atomic types that have the same interface as the ones in sync/atomic. We currently don't need these to be atomic (because the scheduler is entirely cooperative), but once we add support for a scheduler with multiple threads and/or preemptive scheduling we can trivially add some type aliases under a different build tag in the future when real atomicity is needed for threading.
Configuration menu - View commit details
-
Copy full SHA for 83dac2f - Browse repository at this point
Copy the full SHA 83dac2fView commit details -
runtime: prepare the leaking GC for concurrent operations
This uses the internal/llsync package to convert some non-atomic operations to pseudo-atomic operations that will become truly atomic on systems that need this (such as multicore chips and when we implement true parallelism on Linux).
Configuration menu - View commit details
-
Copy full SHA for 1be9858 - Browse repository at this point
Copy the full SHA 1be9858View commit details
Commits on Nov 1, 2024
-
runtime: move scheduler code around
This moves all scheduler code into a separate file that is only compiled when there's a scheduler in use (the tasks or asyncify scheduler, which are both cooperative). The main goal of this change is to make it easier to add a new "scheduler" based on OS threads. It also fixes a few subtle issues with `-gc=none`: - Gosched() panicked. This is now fixed to just return immediately (the only logical thing to do when there's only one goroutine). - Timers aren't supported without a scheduler, but the relevant code was still present and would happily add a timer to the queue. It just never ran. So now it exits with a runtime error, similar to any blocking operation.
Configuration menu - View commit details
-
Copy full SHA for 0bc7d3e - Browse repository at this point
Copy the full SHA 0bc7d3eView commit details -
internal/task: add cooperative implementation of Futex
See the code comments for details. But in short, this implements a futex for the cooperative scheduler (that is single threaded and non-reentrant). Similar implementations can be made for basically every other operating system, and even WebAssembly with the threading (actually: atomics) proposal. Using this basic futex implementation means we can use the same implementation for synchronisation primitives on cooperative and multicore systems. For more information on futex across operating systems: https://outerproduct.net/futex-dictionary.html
Configuration menu - View commit details
-
Copy full SHA for 00980b5 - Browse repository at this point
Copy the full SHA 00980b5View commit details -
internal/task: implement PMutex
PMutex is a mutex when threading is possible, and a dummy mutex-like object (that doesn't do anything) otherwise.
Configuration menu - View commit details
-
Copy full SHA for c0bdb4a - Browse repository at this point
Copy the full SHA c0bdb4aView commit details -
sync: implement WaitGroup using a futex
Code size for the cooperative scheduler is nearly unchanged.
Configuration menu - View commit details
-
Copy full SHA for c48233d - Browse repository at this point
Copy the full SHA c48233dView commit details -
Configuration menu - View commit details
-
Copy full SHA for efd60ca - Browse repository at this point
Copy the full SHA efd60caView commit details -
Make sure the object is locked when trying to modify it. Binary size seems unaffected when not using threading.
Configuration menu - View commit details
-
Copy full SHA for 18443c1 - Browse repository at this point
Copy the full SHA 18443c1View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2c036dc - Browse repository at this point
Copy the full SHA 2c036dcView commit details
Commits on Nov 3, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 98e7150 - Browse repository at this point
Copy the full SHA 98e7150View commit details -
runtime: refactor GC mark phase into gcMarkReachable
This is a small refactor to prepare GC marking for multithreaded stop-the-world.
Configuration menu - View commit details
-
Copy full SHA for 5f0f814 - Browse repository at this point
Copy the full SHA 5f0f814View commit details -
runtime: make conservative and precise GC MT-safe
Using a global lock may be slow, but it is certainly simple and safe. If this global lock becomes a bottleneck, we can of course look into making the GC truly support multithreading.
Configuration menu - View commit details
-
Copy full SHA for b927048 - Browse repository at this point
Copy the full SHA b927048View commit details -
Move common functions to scheduler.go. They will be used both from the cooperative and from the threads scheduler.
Configuration menu - View commit details
-
Copy full SHA for bca037e - Browse repository at this point
Copy the full SHA bca037eView commit details -
sync: implement RWMutex using futexes
Somewhat surprisingly, this results in smaller code than the old code with the cooperative (tasks) scheduler. Probably because the new RWMutex is also simpler.
Configuration menu - View commit details
-
Copy full SHA for 341e6d4 - Browse repository at this point
Copy the full SHA 341e6d4View commit details
Commits on Nov 4, 2024
-
This actually simplifies the code and avoids a heap allocation in the call to Wait. Instead, it uses the Data field of the task to store information on whether a task was signalled early.
Configuration menu - View commit details
-
Copy full SHA for 036e8a5 - Browse repository at this point
Copy the full SHA 036e8a5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 6ae73cb - Browse repository at this point
Copy the full SHA 6ae73cbView commit details -
Configuration menu - View commit details
-
Copy full SHA for d328dd4 - Browse repository at this point
Copy the full SHA d328dd4View commit details