If I understand correctly, that would prevent me from starting any other 
goroutines. The following program deadlocks:

package main

import (
    "log"
    "runtime"
    "time"
)

func init() {
    runtime.LockOSThread()
}

func main() {
    go func() {
        for range time.After(time.Second) {
            log.Print("tick")
        }
    }()

    block := make(chan struct{})
    <-block
    log.Print("done")
}




On Saturday, December 14, 2019 at 11:45:53 AM UTC-8, Ian Lance Taylor wrote:
>
> On Sat, Dec 14, 2019 at 11:31 AM <buch...@gmail.com <javascript:>> wrote: 
> > 
> > I'd really love to get that LockOSThread call out of the main function 
> and hide it away inside a library along with the other internal 
> implementation details. Is that possible? As far as I can tell, it's not 
> possible to ensure that a goroutine runs on the main thread without locking 
> it directly from the main() function. 
>
> I don't know if this helps, but you can lock the main goroutine to a 
> thread by calling LockOSThread in an init function. 
>
> Ian 
>

-- 
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/e4ac1c49-0fbf-4f69-8dcc-64d91e7f3536%40googlegroups.com.

Reply via email to