Making the statistics application concurrent
In this section of this chapter, we are going to convert the statistics application into a concurrent application that uses goroutines. However, instead of using channels, we are going to use a different approach that prevents deadlocks, while making the overall design of the program much simpler. Apart from that, there is also a version of stats.go
named statsNC.go
that does not create any goroutines and processes the input files sequentially.
We are only going to present the implementation of the main()
function of stats.go
because this is where the logic of the utility is found. However, minor additional changes exist for taking advantage of goroutines. The most time-consuming part of stats.go
is the normalization of the time series.
What is impressive is that we converted stats.go
into a concurrent application using a minimal amount of changes that mainly have to do with goroutine synchronization—this is a good...