Say for example that I want to populate this matrix:
| 0 | 0 | 0 | 0 |
| 0 | 1 | 2 | 3 |
| 0 | 2 | 3 | 4 |
| 0 | 3 | 4 | 5 |
Specifically, I want to populate it so that each cell follows the rule,
In english, a cell's value is one greater than the maximum of its top
, left
, and topleft
neighbors' values.
Because each cell only has three dependencies (its top
, left
, and topleft
neighbors), I can populate the cell at m[1][1]
(the 1
), and once that's populated, I can populate the cells marked 2
as all of their dependencies are already populated.
| 0 | 0 | 0 | 0 | | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | ---\ | 0 | 1 | 2 | 0 |
| 0 | 0 | 0 | 0 | ---/ | 0 | 2 | 0 | 0 |
| 0 | 0 | 0 | 0 | | 0 | 0 | 0 | 0 |
How can I spin up 1 go routine, then 2, then 3, then 4..., to populate each diagonal of this matrix? Perhaps more specifically, how can I wait on the neighbors to finish before beginning the dependent cell?
[EDIT]: Thanks for the comment, @Zippoxer! To clarify, I'm asking what the syntax is in Go to run a go-routine that depends on another finishing first. Because multiple new go-routines can start when just one go-routine finishes, it's not as simple as just calling things without concurrency!