Comments (4)
Another issue I'm having is enormous pauses that seem to happen for no reason. For example, in the uploaded image you can see "LuaMan::Update() taking obscene amounts of time, on the order of 5ms, doing literally nothing expect for -wait() ing on tasks that have already finished (the Lua Garbage Collection tasks to the left, which are completed long before the function is even called). No other thread is busy and in fact CPU usage just is effectively nothing at this point.
EDIT:
Okay, fixed this one. The issue is that a multi_future doesn't clear the existing futures after waiting on them. I needed to reconstruct the multi_future after each use to stop unused pointless futures hanging around. On that note... any chance for a multi_future.clear()?
from thread-pool.
Another feature request would be the ability to ask if a multi-future is complete without explicitly waiting on it, as well as general wait_until() and wait_for() on multifuture.
from thread-pool.
I'm working on a user interface which uses this thread pool for loading files from disk; similar functionality would be quite useful as I'd like to prioritise a certain type of file request (but continue loading the other files in the background).
Perhaps there could be a variant of the thread pool which uses a priority queue for tasks and allows an integer priority value to be passed when submitting tasks?
from thread-pool.
Hi @Causeless and @jakeanq and thanks for the suggestions! In fact, most of your suggestions are already being implemented in the upcoming v4.0.0 release.
Is it possible to differentiate task priority and/or thread-pool priority? Generally any task .wait()-ed upon I'd hope to be performed ASAP However, for my specific usage case, not only would we need to be able to push these Lua GC tasks to the front of the queue, but we need to actively preempt thread priority away from the pathfinding tasks to handle the higher-importance tasks.
Given that tasks cannot be terminated early or swapped from, I imagine I'd need to use two thread pools. In that case, would it be possible to give one threadpool priority to be preferentially scheduled towards? I'm not sure if this is reasonably doable and certainly unsure about if it's reasonably doable in a portable manner, but it would be very useful.
- The new release will allow access to the
std::thread::native_handle()
of each thread in order to implement OS-specific priority. This means you can have two thread pools, one with high priority and one with low priority. Note that this is not portable, but can be made portable if you detect the OS and use eitherpthread.h
on Linux/macOS orwindows.h
on Windows. - The new release will implement a priority queue for the thread pool. This is something I'm currently working on and will most likely use a combination of
std::priority_queue
along with a normalstd::queue
for maximum performance. This means you can ensure that tasks with higher priority are executed from the queue first (note that this differs from OS priority, which is more about resource access than order of execution).
Furthermore, it might be useful to just ignore the Lua GC this frame and just continue, until the thread gets around to dealing with it. For this, I'd need to be able to pause (or purge) only a specific task to stop it from starting during the Lua update, without pausing the entire threadpool or affecting other tasks. Is this possible?
Terminating, pausing, or purging individual tasks is not something that can be implemented in the thread pool, since once the task is executed, the thread pool cannot intervene in its code. However, you can embed a "kill switch" (or "pause switch") in the task on your own, and check it occasionally within the internal loop(s) of the task itself.
The issue is that a multi_future doesn't clear the existing futures after waiting on them. I needed to reconstruct the multi_future after each use to stop unused pointless futures hanging around. On that note... any chance for a multi_future.clear()?
Sure, I can add that in v4.0.0.
Another feature request would be the ability to ask if a multi-future is complete without explicitly waiting on it, as well as general wait_until() and wait_for() on multifuture.
As far as I know, it is currently impossible in C++ to check if a future is complete without explicitly waiting on it. You can use wait_until()
and wait_for()
to check for that indirectly. I'll think about how this can be implemented for all futures in a multi_future
.
from thread-pool.
Related Issues (20)
- [BUG] shared_ptr is not being copied in parallelize_loop HOT 6
- [REQ] Getting thread ids HOT 3
- Performance very slow HOT 1
- [REQ] Balanced workload for push_loop HOT 1
- [REQ] Document unexpected cleanup of tasks in worker HOT 1
- [BUG ?] multiple definitions get_index, get_pool link fails with VS 2022 HOT 4
- Support Task Prepending (executing higher priority tasks first) HOT 1
- Place private classes at head of file HOT 2
- Error linking with version 4.0.0 HOT 1
- [REQ] Q? HOT 1
- [REQ] Allow compiling with exceptions disabled. HOT 8
- [REQ] Can the threads in a pool be pinned to specific cores? HOT 1
- [REQ] ability to set threads to 0, and have everything execute serially HOT 3
- [REQ] does this library support recursive/nested tasks? HOT 5
- [REQ] Explain destructor behavior for thread_pool HOT 4
- [REQ] Add compiler flag/define to make threadpool use a stack instead of queue HOT 3
- Get rid of shared pointer for submitted tasks promises HOT 1
- [REQ] Wait on any task in multi_future and thread_pool HOT 2
- [BUG] Thread pool is NOT avaliable when it was created. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thread-pool.