Standard library / runtime

runtime.LockOSThread()

Binds the calling goroutine to its current operating-system thread until balanced unlocks. Useful for thread-affine APIs, not general concurrency. Expected stdout: 'locked\n'.

Formal Syntax & Structure

go syntaxgo
func LockOSThread()

Working Example

Example Snippetgo
package main
import (  "fmt"  "runtime")
func main() { runtime.LockOSThread(); defer runtime.UnlockOSThread(); fmt.Println("locked") }
Go Reference