My Profile Photo

Tom Bell

Go, Swift, and JavaScript Hacker
Northern Quarter, Manchester

Debugging with a MacBook CPU fan

Just a quick anecdote from last Saturday evening while Martin and I were pairing on our project.

We were just switching over who was driving the pairing, and I hear my MacBook Pro CPU fan begin to take off. I ask out loud, what could it be? So I open Activity Monitor to check what is using the CPU.

I had left our project running while we were testing something, and it was using 110% CPU. We were initially left confused as to why this was happening, so I killed the process, and ran it again to check. Yup, it was instantly using 100%+ CPU again.

Last week we added a loop into our main entry point, to continually check that a sub-system is running.

for {
    if !peersystem.IsRunning() {


Martin explained something about the runtime.Gosched() to me last week when we added this, thinking that we didn’t have to include a time.Sleep() call in the loop.

We spent some time wondering if we had a bug in the peersystem.IsRunning() code path, but no avail. So I was adamant that the runtime.Gosched() was the issue and probably didn’t work how Martin thought he understood it.

Changing the runtime.Gosched() to a time.Sleep(1 * time.Second), I re-ran the process, and boom, <1% CPU.

Listen to your CPU fans people!