VC++ thread pool demo (with source code)

VC++ commonly used functions package code a series of articles and source code (advertisement, haha, look at the series and then decide whether to subscribe)

https://blog.csdn.net/kaizi318/article/details/108846326

The source code demo has been uploaded to the Baidu network disk: permanent effective, the code realizes the function of the thread pool, usually when we deal with the same task, it takes a long time.

It does not affect the work of the main thread! So we have to figure out when we need to use the thread pool! Generally used in server socket communication scenarios is the most used

Client connection concurrent... etc.

When there are fewer tasks to be processed, we can create threads to handle them by ourselves, but in high concurrency scenarios, we need to process a lot of tasks. Because of the high overhead of creating and destroying threads, frequent thread creation will greatly reduce the system effectiveness.

At this point, we can use the thread pool, and the threads in the thread pool can be reused after executing a task without being destroyed. Reasonable use of thread pool has the following advantages:

1. Reduce resource overhead. By reusing threads, the cost of creating and destroying threads is reduced.

2. Multiple threads execute tasks concurrently to improve the response speed of the system.

3. The threads can be allocated, tuned and monitored uniformly to improve the manageability of the threads.

This thread pool is only supported on windows, because the Microsoft encapsulated template <class Worker, class ThreadTraits=DefaultThreadTraits, class WaitTraits=DefaultWaitTraits>
class CThreadPool:
    public IThreadPoolConfig

CTh

Guess you like

Origin blog.csdn.net/kaizi318/article/details/108900799