Page MenuHomeWildfire Games

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

Authored by wraitii on Apr 20 2021, 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.Apr 20 2021, 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.Apr 20 2021, 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.Apr 20 2021, 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.Apr 20 2021, 5:56 PM

I'm using wait_for which takes chrono types.

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

Stan added a comment.Jun 3 2021, 5:59 PM

This can definitely be used by the soundmanager too.

Else it would hog a thread like so with pauses from 500ms default to 50ms stress. (This is combat demo huge) Might also help to simplify the weird logic with the distress time to 500ms. (Takes about 1ms on my machine to do one loop)

Yeah I have a diff for that. I'll rebase those for A26