Hey y’all,
I’m still getting familiar with multithreading, and I had a case where I thought a thread pool might be useful. I have it implemented and working, just want to make sure I’m doing so correctly.
First, I have a ThreadPool object in my class.
ThreadPool threadPool{3};
I need to make a couple API calls semi frequently, so my class has a timer and when N time interval elapses, I add the jobs to the threadpool.
void Profile::timerCallback()
{
updateCounter++;
if (updateCounter >= 60)
{
//Functions calling the API
auto updateSocial= [&]() { uploadSocialProfile(); };
auto updateLeaderboard= [&]() { updateLeaderboardStats(); };
auto updateUserData= [&]() { uploadUserData(); };
threadPool.addJob(updateSocial);
threadPool.addJob(updateLeaderboard);
threadPool.addJob(updateUserData);
updateCounter = 0;
}
}
As I understand when the job is finished it seems to remove itself from the threadpool, so I think re-adding them every N interval is correct? Idk, any input appreciated!