Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task::arena::execute is not compatible with move-only functors #16

Closed
anton-potapov opened this issue Apr 18, 2017 · 4 comments
Closed

Comments

@anton-potapov
Copy link
Contributor

both task::arena::execute and task::arena::enqueue require it argument to be copyable. So following code simply wont compile:

task_arena{}.execute( 
       [p = std::unique_ptr<int>(new int)] () {
		*p = 1;
	}
); 
@alexey-katranov
Copy link
Contributor

alexey-katranov commented Apr 26, 2017

Hi Anton!

Thank you for the reported problem. I could not reproduce the problem with tbb::task_arena::execute (because it uses references inside the implementation); however, tbb::task_arena::enqueue has this issue. We will investigate if we are able to fix it

If using move-only objects is critical, you may want to use the following work-around:

tbb::task_arena{}.enqueue( 
+        [l = new auto(
        [p = std::unique_ptr<int>(new int)]() {
            *p = 1;
        }
+        )] { l->operator()(); delete l; }
);

Regards,
Alex

@anton-potapov
Copy link
Contributor Author

anton-potapov commented May 29, 2017

IMHO, the work-around is not functional when cancellation appears, and in this particular case leads to memory leak, as delete l; will not be called (as it called from lambda body only, and not from lambda object destructor). Thus the only work-around i see is "move via copy" wrappers, which IMHO is ugly :)

@alexey-katranov
Copy link
Contributor

alexey-katranov commented May 29, 2017

Let me improve it a bit:

tbb::task_arena{}.enqueue(
+   [l = [](auto&& p) { typedef typename std::decay<decltype(p)>::type T; return std::make_shared<T>(std::forward<T>(p)); } (
    [p = std::unique_ptr<int>(new int)]() {
        *p = 1;
    }
+   )] { (*l)(); }
);

@PovelikinRostislav
Copy link

Hi Anton,

We released fix for your issue and would like you to confirm that it works as you wished.
Could you please check the status?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants