Thread Pool

Initially, my pathfinding algorithm led to performance loss when multiple enemies on a vast map attempted to calculate paths simultaneously, sometimes every frame. To enhance this, I devised a solution where, regardless of their current state, enemies could persist in their activities while awaiting the completion of path calculations. This transition ensured that upon receiving their calculated paths, they could effortlessly shift to the next state, utilizing the paths without hindering much of performance. That solution was thread pool, by making use of modern CPU, which usually come with multi-cores and threads. I encountered a subsequent challenge where certain tasks needed to be executed as swiftly as possible, which current thread pool class could not meet the requirement. To address this, I designed a separate priority queue for such tasks, assigning them a priority range from 0.0 to 1.0, with higher numbers indicating higher priority. This ensured that tasks in the priority queue were executed before those in the normal queue. After a code review, my classmates and I engaged in a discussion concerning the potential issue of certain tasks never begin executed if higher priority tasks were continuously added.

"What if some tasks remain unexecuted due to the constant influx of higher priority tasks?"

The solution I had in mind was some sort of timer for every tasks in queue. Since this 'potential issue' had not yet occurred, I decided it wasn't necessary to allocate time to address it immediately. Instead, I documented it, along with other potential issues and improvements, for future consideration.