gothread

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2025 License: MIT Imports: 2 Imported by: 0

README

gothread

Overview

Use consistent API to operate threads in Go language.

Supported OS:

Windows √

Linux √

MacOS √

Usage

import this package:

import "github.com/xuges/gothread"

Get current thread id:

id := gothread.GetId()
fmt.Println("current thread id:", id)

Pin to current thread:

gothread.Pin()
defer gothread.Unpin()

Run on thread stack:

// run on current thread
gothread.Run(func() {
    println(gothread.GetId())
})

// run on new thread
go gothread.Run(func() {
    println(gothread.GetId())
})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

Close the OS thread

NOTE: must call on non-pined goroutine

func GetId

func GetId() int

GetId returns the current OS thread id

func Pin

func Pin()

Pin locks the current goroutine to OS thread

func Run

func Run(task func())

Run runs the task on OS thread

func Unpin

func Unpin()

Unpin unlocks the pined OS thread and current goroutine

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL