Build Your Own Threadpool With C++
Why Threadpool Matters
Why on the earth do we need thread-pool? The answer is obvious: for doing jobs behind the scenes.
That is, saying, you have a constant stream of incoming tasks to complete, and most of which either incur heavy computation or invovle device I/O, you definitely don’t want to execute them on your main thread, because it will block your main thread until the job is done, making your application less responsive.
However, with thread-pool, you can simply submit a task to the pool, then continue what was doing; the task will eventually be completed on a thread of the thread-pool.
If your processor has multiple cores, the task is possibly performed concurrently with your jobs on the main thread.
What Should a Threadpool Provide
Before we switch our focus to editor, we are better to think twice about what we can do with the thread-pool we will build.