You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
std::result_of has been deprecated in C++ 17. Use std::invoke_result instead.
We should use std::invoke instead of write f(args...) directly.
We could use initializer in lambda's capture list in C++ 14, so instead of make_shared<std::packaged_task> and copying it into the lambda we can write [task = std::move(task)].
Reacted by Abhinav Singh, mshingote, Ellen Emilia Anna Zscheile, Max Azoury, Binbin sun, Aaron Boxer, xiaoLiuxiaoLiuxiaoLiu, Vladimir Gamalyan, MahouBootCamp2, Julien Marrec and 2 more
@jhasse Oops! The standard requires F to be CopyConstructible...
Initializes the target with a copy of f. If f is a null pointer to function or null pointer to member, *this will be empty after the call. This constructor does not participate in overload resolution unless f is Callable for argument types Args... and return type R. (since C++14)
The solution is to replace std::function with an implementation which also works with move-only Callables. I've found fu2::unique_function from here: https://github.com/Naios/function2
@jhasse Oops! The standard requires F to be CopyConstructible...
Initializes the target with a copy of f. If f is a null pointer to function or null pointer to member, *this will be empty after the call. This constructor does not participate in overload resolution unless f is Callable for argument types Args... and return type R. (since C++14)
@aphenriques Why did you change the build system back to Makefiles? I'm just curious, because I think they would be a bigger maintenance burden than a CMake or meson-based system.
@zserik All projects I work with use Make as the build system. CMake or other modern build systems could probably offer greater flexibility, however, I think I would have less trouble maintaining the workflow of my code base. Moreover, the makefiles are quite automated.
By the way, thanks for your contribution. Soon, some of your code will be in production.
Activity
jhasse commentedon Apr 17, 2018
I've managed to implement 1: jhasse@428aeae
But I'm having troubles with 3. This is what I've come up with so far:
But GCC complains:
Why doesn't it use the move constructor of
packaged_task?LYP951018 commentedon Apr 17, 2018
@jhasse Oops! The standard requires
Fto beCopyConstructible...http://en.cppreference.com/w/cpp/utility/functional/function/function
So maybe we have to stick with
shared_ptrhere.jhasse commentedon Apr 17, 2018
We could use unique_ptr though :)
jhasse commentedon Apr 17, 2018
Okay I misunderstood the problem. https://stackoverflow.com/questions/32486623/moving-a-lambda-once-youve-move-captured-a-move-only-type-how-can-the-lambda
The solution is to replace
std::functionwith an implementation which also works with move-only Callables. I've foundfu2::unique_functionfrom here: https://github.com/Naios/function2The end result looks like this: jhasse@f9b1774
Do you simply mean replacing
(*task)();withstd::invoke(*task)? Or getting rid ofstd::bind?jhasse commentedon Apr 18, 2018
Or even easier: Simple move the packaged_task as suggested here: #51
mshingote commentedon Feb 28, 2019
Can I create a branch and pull request for this issue?
jhasse commentedon Feb 28, 2019
I don't think this repository is maintained any more, so I wouldn't bother with a PR. See my C++17 fork here: https://github.com/jhasse/ThreadPool
fogti commentedon Feb 28, 2019
another fork: https://github.com/zserik/ThreadPool
I try to merge all important changes.
mshingote commentedon Mar 5, 2019
Great Thanks! @jhasse and @zserik 👍
ganler commentedon Jul 24, 2019
@LYP951018 Actually, why not simply use raw pointers with some exception code ...
Without considering exceptions, you may just:
I don't really know if this approach could solve ur problem...
aphenriques commentedon Dec 10, 2019
Yet another fork: https://github.com/aphenriques/thread
It slightly modifies @zserik's https://github.com/zserik/ThreadPool and adds some utilities.
fogti commentedon Dec 10, 2019
@aphenriques Why did you change the build system back to
Makefiles? I'm just curious, because I think they would be a bigger maintenance burden than aCMakeormeson-based system.aphenriques commentedon Dec 10, 2019
@zserik All projects I work with use Make as the build system. CMake or other modern build systems could probably offer greater flexibility, however, I think I would have less trouble maintaining the workflow of my code base. Moreover, the makefiles are quite automated.
By the way, thanks for your contribution. Soon, some of your code will be in production.
fawdlstty commentedon Apr 24, 2021
yet another similar project: taskpool, it can: