gobyexample/examples/stateful-goroutines/stateful-goroutines.sh
Mark McGranaghan 6a58750728 Consistently use Sleep in state-management examples
Consistently use `time.Sleep`, instead of `runtime.Gosched`, to ensure all
goroutines can make progress. `Gosched` wasn't working in the playground
(ref #149).

Also stop trying to compare operation rates. This was tenuous given e.g. how
short the programs ran for, and with the `Sleep`s we now expect the rates to
be similar anyways.
2016-12-27 10:13:03 -08:00

16 lines
590 B
Bash

# Running our program shows that the goroutine-based
# state management example completes about 80,000
# total operations.
$ go run stateful-goroutines.go
readOps: 71708
writeOps: 7177
# For this particular case the goroutine-based approach
# was a bit more involved than the mutex-based one. It
# might be useful in certain cases though, for example
# where you have other channels involved or when managing
# multiple such mutexes would be error-prone. You should
# use whichever approach feels most natural, especially
# with respect to understanding the correctness of your
# program.