Created
September 7, 2012 14:05
-
-
Save shreyansb/3666521 to your computer and use it in GitHub Desktop.
this will block the cpu entirely
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"runtime" | |
"time" | |
) | |
func main() { | |
// THIS is totally required; without it, you're blocking the CPU regardless | |
// of whether you use LockOSThread or not. | |
runtime.GOMAXPROCS(4) | |
// arbitrary CPU-blocking function | |
go cpublock() | |
go cpublock() | |
go cpublock() | |
go cpublock() | |
for { | |
fmt.Println("hey") | |
time.Sleep(time.Second) | |
} | |
} | |
func cpublock() { | |
x := 0 | |
for { | |
x += 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this will print 'hey' once, then when the time.Sleep yields to the scheduler, the last cpublock goroutine will start.