GithubHelp home page GithubHelp logo

Comments (5)

mtrebi avatar mtrebi commented on June 30, 2024 5

Hey! I am glad you liked the readme, it took me some time to write it 👍

Regarding your question, yes, there's a way to pass member functions. Your approach doesn't work because the submit function is implemented in such way that the first argument is always the function and the following arguments are the parameters of the function. Probably I could override the submit function or something similar to make it easier...In the meantime, you can solve the issue using std::bind. The idea is basically to create a new function that is simply the function we want to call with the specific object from which we want to call it.

auto func = std::bind(&A::func_1, &objA);
pool.submit(func);

You could do exactly the same using lambda expressions,

pool.submit([&]() {objA.func1(); });

Hope this helps!

from thread-pool.

rajenk avatar rajenk commented on June 30, 2024

Thanks. I will give std::bind a try or use lambda expressions. I will post the results to help answer others visiting your project.

Appreciate your quick reply.

from thread-pool.

mtrebi avatar mtrebi commented on June 30, 2024

Whenever I have some more time I will try to add an easier way to do it. I am really busy lately...

from thread-pool.

rajenk avatar rajenk commented on June 30, 2024

I tried both bind and lambda approach. Both did not work the way I wanted in my app! So using a C wrapper functions to invoke member functions via the class object. This works for me as I intended.

from thread-pool.

mtrebi avatar mtrebi commented on June 30, 2024

I tried both options and they worked for me. What do you mean with ¨Both did not work the way I wanted?

Anyway, I am glad you found the solution to your problem 👍

from thread-pool.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.