Hi, sorry for late response. Your solution is very inspiration! I solved the problem with letting pango call entering go domain and lock on os thread, then back to c domain.
Thank you very much! cheers, changkun On Saturday, September 29, 2018 at 6:16:10 PM UTC+2, Tamás Gulácsi wrote: > > > 2018. szeptember 29., szombat 17:10:25 UTC+2 időpontban changkun a > következőt írta: >> >> >> >> On Saturday, September 29, 2018 at 4:03:42 PM UTC+2, Tamás Gulácsi wrote: >>> >>> Create One (1) goroutine with LockOSThread and let it get the todo and >>> response channel from a channel and send the response back when ready, and >>> make all other goroutines communicate with this one and only one >>> pango-dedicated goroutine. Which is locked to a thread. >>> >> >> Can't do that at the moment, reason in above. >> > > I tought something like: > > type todo struct { > FuncToCall string > Args []interface{} > Response ch chan<- response > } > type response struct { > ResultCode int > Err error > } > > var todoCh = make(chan todo) > > go func(ch <- todo) { > runtime.LockOSThread() > defer runtime.UnlockOSThread() > for t := range ch { > switch t.FuncToCall { > ... > } > t.Response <- response{Err:nil, ResultCode:0} > } > }() > > func handleConnection(timeout) error { > ch := make(chan response, 1) > ctx, cancel := context.WithTimeout(context.Background(), timeout) > defer cancel() > select { > case <-ctx.Done(): > // timeout > return ctx.Err() > case todoCh <- todo{FuncToCall:..., Response:ch}: > select { > case <-ctx.Done(): > return ctx.Err() > case resp := <-ch: > // success! > return nil > } > } > } > > > I don't feel that abstracting out the C (Pango) calls into an interface > with maybe several implementations (C or Go) would be such a great > undertaking, > but would ease up writing correct code. > > And anyway you have to call that Pango thing from one thread. > -- 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. For more options, visit https://groups.google.com/d/optout.