I came across a similar issue when I was working with a heartbeat feature for Macs. The same code ran as expected on Linux machines. In the end, the issue was with Sleep Mode in the Mac machine. When a Mac goes to sleep, time based functions seem to pause. They resume when the machine is woken up again. But if you are doing critical tasks that are based on time duration, they will fail.
On Wednesday, September 4, 2019 at 1:49:42 PM UTC+5:30, Tor Langballe wrote: > > I'm running a mac cocoa event loop, and calling a go ticker: > > void StartApp() { > [NSAutoreleasePool new]; > [NSApplication sharedApplication]; > [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; > [NSApp run]; > } > > func test() { > last := time.Now() > ticker := time.NewTicker(time.Second) > for range ticker.C { > t := time.Now() > diff := t.Sub(last) > if diff > time.Second*2 { > fmt.Println("Tick slow:", diff) > } > last = t > } > } > > > func main() { > go test() > C.StartApp() > } > > currenly just running the go program from the terminal, though I got > similar results packaging it into an app. > > I soon get very long periods between ticker fires: > > Tick slow: 3.501350114s > Tick slow: 5.551485377s > > This seems to only happen with > > [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; > > NSApplicationActivationPolicyProhibited and > NSApplicationActivationPolicyAccessory don't cause this. > > I assume it's the event loop in [NSApp run] that is causing this, but > don't know how to start making a mac appliction with goroutines and tickers > that don't get blocked. > > Does anybody know how to avoid this and why it is happening? > > tor > > > > -- 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/927c609c-d270-4085-8d7b-069f273b7417%40googlegroups.com.