olahol / mainthread

Run functions in Go's main thread.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mainthread

GoDoc

Run functions in Go's main thread. Package of Russ Cox's code from golang-nuts

From LockOSThread:

Some libraries, especially graphical frameworks/libraries like Cocoa, OpenGL, libSDL all require it's called from the main OS thread or called from the same OS thread due to its use of thread local data structures. Go's runtime provides LockOSThread() function for this, but it's notoriously difficult to use correctly.

Install

go get github.com/olahol/mainthread

Example

package main

import (
	"fmt"
	"github.com/olahol/mainthread"
)

func main() {
	go func() {
		mainthread.Do(func() {
			fmt.Println("Hello from main thread")
		})
		mainthread.Quit()
	}()

	mainthread.Main()
}

About

Run functions in Go's main thread.

License:BSD 2-Clause "Simplified" License


Languages

Language:Go 100.0%