I am writing a golang program that has to perform multiple download requests at a time utilizing goroutines running in parallel (using GOMAXPROCS). In addition, there is a form of state kept, which is which components have been downloaded and which components are left to be downloaded. The mutex solution would be to lock this structure keeping track of which components have been successfully downloaded. I have read that when attempting to keep state, mutexes are the best option.
However, I am wondering what would be a solution utilizing channels (passing ownership instead of providing exclusive access to state) instead of mutexes, or are mutexes the best option?
P.S. So far I have thought of passing the global structure keeping state between go routines which are all utilizing one channel (a read-write channel). A go routine attempts to read the structure from the channel and then write it back when it's done.The problem I found with this, is that when the last running go routine [assume all others have finished and stopped running] gives up its posession of the structure by writing to the channel, it will result in deadlock since there are no receivers. In addition, this is still attempting to use channels as mutexes [attempting to provide exclusive access].