Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ehaliewicz/b7a1eedf67dac1b110ed9889b7391a9b to your computer and use it in GitHub Desktop.

Select an option

Save ehaliewicz/b7a1eedf67dac1b110ed9889b7391a9b to your computer and use it in GitHub Desktop.
typedef struct {
int tile_x, int tile_y;
int num_polys; // idk just put whatever here
volatile s64 finished; // used to let the master thread know when this thread is finished
} thread_params;
thread_pool_function(rasterize_tile_thread, arg_var)
{
thread_params* tp = (thread_params*)arg_var;
rasterize_tile(tp->tile_x, tp->tile_y, ...);
InterlockedIncrement64(&tp->finished);
}
thread_pool* tp = thread_pool_create(NUM_THREADS);
thread_params parms[NUM_THREADS];
for(int i = 0; i < NUM_THREADS; i++) {
// setup parameters for thread i
// perhaps the tile bounds in screen-space
parms[i].tile_x = ...;
params[i].finished = 0;
}
// this starts up the threads
for(int i = 0; i < NUM_THREADS; i++) {
thread_pool_add_work(tp, raycast_wrapper, &parms[i]);
}
// now we just wait until all are finished
while(1) {
int finished = 0;
for(int i = 0; i < NUM_THREADS; i++) {
if(parms[i].finished) {
finished++;
}
}
if(finished == NUM_THREADS) {
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment