Update The proposal is #64777 (comment).
Proposal Details
This proposal is a less flexible but perhaps easier to implement and maintain alternative to #64755. See that issue for background and motivation for non-main packages to take control of the main thread.
I propose adding a new function, runtime.RunOnMainThread, for running a function on the startup, or main, thread. In particular,
package runtime
// RunOnMainThread runs a function immediately after program initialization on a
// goroutine wired to the startup thread. It panics if called outside an init
// function, if called more than once, or if [runtime.LockOSThread] has already
// been called from an init function.
// Once RunOnMainThread is called, later LockOSThread calls from an init function
// will panic.
func RunOnMainThread(f func())
This is the complete proposal.
Variants
Just like #64755, an alternative spelling is syscall.RunOnMainThread optionally limited to GOOS=darwin and GOOS=ios.
Update The proposal is #64777 (comment).
Proposal Details
This proposal is a less flexible but perhaps easier to implement and maintain alternative to #64755. See that issue for background and motivation for non-main packages to take control of the main thread.
I propose adding a new function,
runtime.RunOnMainThread, for running a function on the startup, or main, thread. In particular,This is the complete proposal.
Variants
Just like #64755, an alternative spelling is
syscall.RunOnMainThreadoptionally limited toGOOS=darwinandGOOS=ios.