Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread pool #3

Open
kvark opened this issue Apr 15, 2015 · 1 comment
Open

Thread pool #3

kvark opened this issue Apr 15, 2015 · 1 comment

Comments

@kvark
Copy link
Member

kvark commented Apr 15, 2015

Possible interface could be:

enum SpawnMode {
   Unlimited, // currently implemented mode, one thread per task
   ThreadPool(u8), //count
   AffinityMask(u64), //mask
}
@ghost
Copy link

ghost commented May 5, 2015

Doing some research the normal strategy is a work-stealing thread pool that uses random selection of the victims. The random selection use a back off algorithm.

I think this a good strategy for small short lived tasks. Tasks can be started at any time, by any thread. If the thread is a scheduler thread the task will be enqueued into its work queue. If the thread is outside of the threadpool, it will use a channel of some sort to inject the tasks into the pool from outside. This could just look like another stealer queue to the other threads.

Tasks should get flagged if they want to run in the pool, or run on a dedicated thread. There is actually no real difference for the worker. The worker will run a thread stealing task, the difference would be that the scheduler would see that stealer task and request a new pool thread be created to take its place.

I think it makes sense to have two watermarks, a low watermark and a high watermark for worker thread count. Iff starting a thread stealing task would drop the thread count below the high watermark the new thread spawn logic is called. The high watermark would be use to limit the number of pool threads, Since stealing tasks would eventually return the thread, the high watermark can be used to determine if a thread needs to be killed when it goes idle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant