Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 2 down vote accepted

Every time you retire a stage 1 job, figure out which neighboring stage 2 jobs now have their dependencies satisfied, and add them to the job queue at that point. That could be as simple as keeping a counter per chunk, starting at zero and maxing out at 6, incremented every time a neighbor completes stage 1.

If you have access to atomic add operations and the ability to add to the job queue from any thread, this would be pretty simple. If not, you need a single designated worker that is in charge of handling the completion of a stage 1 job, incrementing the counter for all its neighbors, and kicking a stage 2 job when a counter reaches its maximum.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.