I'm writing a go program that constantly receives and processes windows messages in golang. (Go1.7, GOMAXPROCS=8, Windows 10)
Here's my code.. (minimal code) import ( "fmt" "github.com/go-ole/go-ole" "runtime" ) func main () { SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS) runtime.LockOSThread() InitCOM() // Initializes COM Object // (The com object constantly send message to this process) RunTickerGoroutine() // This functions internally launches one goroutine, // which also sends message to the main thread every 30 seconds /* Typical Windows Message Loop */ var m ole.Msg for { ole.GetMessage(&m, 0, 0, 0) fmt.Println(m, ": Got Message!") ole.DispatchMessage(&m) } } func SetPriorityClass() { // Just some some syscalls calling SetPriorityClass of Kernel32.dll ... } So bascially there are two objects(com object and goroutine I launched) which constantly send messages to the main goroutine and this main goroutine processes them with typical message loop.. and it works well most of the time. However, the problem is, sometimes the message loop is getting blocked, and after some amount of time, the message loop resumes and large amount of blocked old messages are getting pumped. I initially thought this is because of main goroutine's OS Thread switching. I thought windows message loop is not getting any message for a while because it's goroutine got switched to other OS Thread for a while. So I added a code runtime.LockOSThread() like above code. But the problem still occurred! So I thought this is probably because of OS Context Switch.. So I added code SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS) to ensure this process to be high priority in windows, and killed all of other cpu intensive processes. But the problem still occurred. I really have no idea how to solve this problem.. Now I'm suspecting that runtime go scheduler is not scheduling my main goroutine(message loop thread) sometimes, and that's why my message loop get blocked for a while. However, I have no idea how to verify it and also solve it. So my question is.. Why the message loop is getting blocked intermittently? How can I solve this problem? (I want my main goroutine(message loop) always working without OS Thread switch (never blocked)) Any helps/ideas will be greatly appreciated. Thanks -- 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.