In my game I separate creation of chunks into two stages. The first is where I generate the heightmap using simplex noise and the 2nd is when I create the actual vertex buffers. I do it like this so that when creating the geometry I can always look at neighboring chunks so I can do decide things like visibility of faces.
Right now I'm working on loading chunks in the background. My first attempt was to create a simple job queue and just push all of the jobs for stage 1 first followed by all the jobs for stage 2. The problem then becomes a thread trying to start a job for the 2nd stage before all the necessary 1st stage jobs are done.
I suppose I could just have another worker thread that waits for all the 1st stage jobs to finish but that seems less than ideal. It also means I can't do anything clever like starting a stage 2 chunk job after that chunk and all surrounding chunks have gone through stage 1 instead of just waiting for all pending chunks to have gone through stage 1.
What is the correct system to use when dealing with dependencies of this kind?