Need to make sure I am using ThreadPool correctly?

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()
    if (updateCounter >= 60)
        //Functions calling the API 
        auto updateSocial= [&]()  {    uploadSocialProfile();    };
        auto updateLeaderboard= [&]()  {    updateLeaderboardStats();    };
        auto updateUserData= [&]()  {    uploadUserData();    };

        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!

Yes you are, nothing wrong the what you posted. But be aware, that you passing your Profile instance to the jobs. Being safe to not run into issues included to stop all jobs in your dtor (if the thread pool is only for that instance) or come up with a shared reference model.