Comments (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.
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.
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.
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.
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)
- Is it redundant with two locks? HOT 2
- Synchronization on shutdown. HOT 5
- Is there a way to have a member method as the executed function? HOT 2
- Author of another thread pool says mtrebi's thread pool fails tests HOT 12
- the runtime is very slow when you have a lot of light functions HOT 2
- Building problem - cmake configure HOT 2
- Would you tell me why you use notify_one instead of notify_all here?
- How to wait for all tasks to finish?
- The output file doesn't output anything on compiling on Windows with MinGW-w64
- Not threadsafe
- 应用层,类的非静态函数不能使用,目前仅静态函数可用 HOT 3
- Bug report: When sub-task are performed quickly, the results are inaccurate HOT 4
- duplicated mutex? HOT 1
- Heap allocation issues HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thread-pool.