Skip to content

runtime/mainthread: new package to manage main thread #64777

@eliasnaur

Description

@eliasnaur

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    In Progress

    Status

    Accepted

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions