I am trying to ultimately end up with a 2D slice where the first dimension is equal to the number of go-routines used and the second dimension is a list of structs that each go-routine is responsible for writing to.
Type:
[][]*Node
Each go-routine will be given an index for the first dimension in the 2d slice and will only append to the list at it's index.
My first instinct was to think this was ok, but if two go-routines simultaneously need to append to their respective lists, this means I am concurrently writing to the first dimension slice.
I was thinking pointers to the second list instead of using raw lists might mitigate this concurrent write... something like:
workCollector := make([]*[]*Node, 5)
for i ; i < 5; i++ {
go.Process(i)
}
func Process(threadNum int){
localList := workCollector[threadNum]
*localList = append(*localList, NewNode(UUID.()))
}
Is this enough to allow each go-routine to append to their own list or should the append happen in a mutex?