Skip to content

proposal: runtime: pair LockOSThread, UnlockOSThread calls #20458

Description

@bcmills

#20395 (comment) reminded me once again of the awkwardness of runtime.UnlockOSThread.

As currently documented, UnlockOSThread is not safe for use in any library code: a library that calls LockOSThread has no way to know whether the caller also called LockOSThread (and hence expects the thread to remain locked). In practice, UnlockOSThread is only safe to use within the package that spawned the goroutine to be locked.

UnlockOSThread could be made safe for use in libraries with one simple change: after N calls to LockOSThread, do not actually unlock the thread until the Nth call to UnlockOSThread. This would make the API a bit easier to use correctly and eliminate a potential source of subtle concurrency bugs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions