Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
cooperative scheduling with cpu intensive tasks, GOMAXPROCS=1
package main
import (
"encoding/json"
"fmt"
"runtime"
"strings"
"sync"
)
const testBytes = `{ "Test": "value" }`
type Message struct {
Test string
}
var wg sync.WaitGroup
func cpuIntensive(p *Message, i int) {
fmt.Printf("Started intensive thing %d\n", i)
for i := int64(1); i <= 1000000; i++ {
json.NewDecoder(strings.NewReader(testBytes)).Decode(p)
}
fmt.Printf("Done intensive thing %d\n", i)
wg.Done()
}
func main() {
runtime.GOMAXPROCS(1)
x := Message{}
wg.Add(2)
go cpuIntensive(&x, 1)
go cpuIntensive(&x, 2)
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.