Timeline for Platform independant thread pool v3
Current License: CC BY-SA 3.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 10, 2020 at 13:24 | history | edited | CommunityBot |
Commonmark migration
|
|
Jun 24, 2014 at 8:52 | comment | added | Tom Myles | Thanks, that was really helpful. I'll go with the other answer since they managed to make it such that a single function handles almost everything. | |
Jun 23, 2014 at 8:06 | history | edited | Yuushi | CC BY-SA 3.0 |
added 176 characters in body
|
Jun 23, 2014 at 8:04 | comment | added | Yuushi |
Yes, my apologies, you're quite right that you'll get a dangling reference there, not sure what I was thinking. Using a shared_ptr seems to be the way to go here, I agree. How are you calling enqueue_task ? In this instance, it will need an actual rvalue reference (so either an inline lambda, or a call to std::move(f) where f is some type implicitly convertible to std::function ). I'd recommend reading isocpp.org/blog/2012/11/…
|
|
Jun 23, 2014 at 7:18 | comment | added | Tom Myles |
Great, although what you did to get the promise inside the lambda will not work, unless the task is started before enqueue_task is complete as it will go out of scope and be destroyed before it is accessed, i.e. a dangling reference. I ended up using a std::shared_ptr to hold the std::promise and std::move 'ing that into the lambda. Also when I use && in the definition of enqueue_task clang says error: no matching member function for call to 'enqueue_task' when I use a std::function<int(int,int)> with arguments.
|
|
Jun 23, 2014 at 6:33 | comment | added | Yuushi |
std::bind has the signature template< class F, class... Args > /*unspecified*/ bind( F&& f, Args&&... args ) hence yes, it should support perfect forwarding (as above). Further, the result of std::bind is movable iff all objects are movable - hence the above solution would only work for the case where all args are movable.
|
|
Jun 23, 2014 at 6:21 | comment | added | Tom Myles |
I've been doing some work on this, and came to the point where std::promise was trying to be copied, I believe this happens because std::function must be CopyConstructible, hence the lambda must be the same, as well as any value not captured by reference, so we cannot capture it directly even if we use std::move . I didn't think to use std::bind, will this allow perfect forwarding of arguments? My solution does not.
|
|
Jun 23, 2014 at 6:09 | history | answered | Yuushi | CC BY-SA 3.0 |