Search code examples
c++multithreadingthreadpool

Taskpool not working while calling task with Arguments


I am creating a threadpool by using "https://github.com/alugowski/task-thread-pool/" and calling task using submit function but getting error

    int Model::sum(int a, int b)
    {

        return 1;
    }

    void Model::SubscribeMLStatusCallBackFn(const MLStatusReceiveCallbackFn& statusCallback)
    {
        m_MLStatusCallback = statusCallback;
        task_thread_pool::task_thread_pool pool;
        std::future<int> sum_future = pool.submit(&sum, 1, 2);
        sum_future.get();
    }

Error :No instance of function template matches the argument list, argument types are: (std::string, CommandLineArgumentTypes)

But same working on

    std::future<int> sum_future = pool.submit([] { return 1; });

Can someone tell me what error I am doing in calling submit using &sum function


Solution

  • What you can try to invoke the sum method is passing both the function and the instance of the class, and further binding the member function to the object.

    std::future<int> sum_future = pool.submit(std::bind(&Model::sum, this, 1, 2));