Created
March 2, 2026 18:31
-
-
Save ehaliewicz/b7a1eedf67dac1b110ed9889b7391a9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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