I want to run the main goroutine on another thread besides the main thread, 
so that the main thread can block in darwin UI code. Is this a safe way to 
do it?

package main

/*
#include <pthread.h>
#include <stdio.h>

void block() {
        printf("Blocking main thread? %d\n", pthread_main_np());
        while(1);
}
*/
import "C"
import (
        "fmt"
        "runtime"
)

func init() {
        runtime.LockOSThread()
        go main()
        C.block()
}

func main() {
        fmt.Println("Blocking main goroutine?", C.pthread_main_np())
}


This prints out the following:

$ go run threadtrick.go
Blocking main thread? 1
Blocking main goroutine? 0

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6b476ab1-c6b6-4f77-91d8-aba2dfbcc314%40googlegroups.com.

Reply via email to