[threads]: Implementing Async callbacks in C++
Recently, I’d written a threadpool library, simplethreadpool, in C++, which allows you to start few threads and facilates assignment of tasks to threads whenever required. This saves the thread-creation overhead and is pretty easy to use. Most of the time, you want to execute a callback after the job is done. For example, After sorting a list of integers, send those integers over the network.
Problem here is that it’s not advisible to wait in main thread.
I think it’s best to use another thread for executing sendDataOverNetwork()
.
Using simplethreadpool, it can be easily achieved.
Refer to this example for more details.