Example #1
0
// getThreadID returns an opaque value that is unique per OS thread.
func getThreadID() uintptr {
	// Darwin lacks a meaningful version of gettid() so instead we use
	// ptread_self() as a proxy.
	return uintptr(unsafe.Pointer(C.pthread_self()))
}
Example #2
0
// OS X cares very deeply if we don't run on the very first thread the OS creates
// why? who knows. it's stupid and completely indefensible. let's use undocumented APIs to get around it.
// apple uses them too: http://www.opensource.apple.com/source/kext_tools/kext_tools-19.2/kextd_main.c?txt
// apple HAS SUGGESTED them too: http://lists.apple.com/archives/darwin-development/2002/Sep/msg00250.html
// gstreamer uses them too: http://cgit.freedesktop.org/gstreamer/gst-plugins-good/tree/sys/osxvideo/osxvideosink.m
func ensureMainThread() {
	// TODO set to nil like the apple code?
	C._CFRunLoopSetCurrent(C.CFRunLoopGetMain())
	// TODO is this part necessary?
	C._CFMainPThread = C.pthread_self()
}
func get_thread_id() string {
	return fmt.Sprintf("%p", C.pthread_self())
}