Page MenuHomeWildfire Games

ThreadPool extension -> Timer for recurrent task & adapt netClient.
Needs ReviewPublic

Authored by wraitii on Tue, Apr 20, 11:17 AM.
This revision needs review, but there are no reviewers specified.



Extends D3848.
The idea is that some tasks, such as the netclient, need to run regularly but are very fast to execute, so a dedicated thread would be "mostly idle". If we have several "mostly idle" threads, they'll end up waking up randomly, pessimising the designe of the thread pool.

Instead, this implements a single 'Timer' thread, that wakes up at fixed intervals (intended to be 'short enough'). There, very fast 'dispatch' tasks are run, that may push work to other workers. The timer thread is intended to go back to sleep ASAP.

The 'recrrent tasks' push work on the other workers, keeping the 'contract' that we have one thread-per-core & efficient resource usage, and the single timer-thread avoids having multiple mostly-idle-threads waking at random times.

This can also easily be adapted for sound & the net server. I think it's better than dedicated threads, since those threads still mostly sleep.
A GPU thread would probably need its own worker, so that's handled by a different use case.

Test Plan

Agree with the concept/design.

Event Timeline

wraitii created this revision.Tue, Apr 20, 11:17 AM

Build failure - The Moirai have given mortals hearts that can endure.

Link to build:

Build failure - The Moirai have given mortals hearts that can endure.

Link to build:

Stan added a subscriber: Stan.Tue, Apr 20, 12:17 PM
Stan added inline comments.

Use timer_time() instead of std::chrono as it was made for it, and I think there are some implem issues with regards to performance with it on windows.

wraitii added inline comments.Tue, Apr 20, 4:50 PM

Can you source that?

I have to include <chrono> for condition_variable anyways, so I'd rather use it in general.

wraitii added inline comments.Tue, Apr 20, 5:56 PM

I'm using wait_for which takes chrono types.

These 3 links seem outdated / not relevant for our compilers.