[Erledigt] std::bind() mit Parameter-Übergabe



  • Hallo,
    ich habe hier ein Thread-Pool, dem ich eine Funktion und entsprechende Argumente übergeben kann:

    template <class F, class... Args>
    std::shared_future<typename std::result_of<F(Args...)>::type> thread_pool::enqueue(F&& f, Args&&... args) {
        using packaged_task_t = std::packaged_task<typename std::result_of<F(Args...)>::type()>;
        using shared_future_t = std::shared_future<typename std::result_of<F(Args...)>::type>;
    
        std::shared_ptr<packaged_task_t> task(
            new packaged_task_t(std::bind(std::forward<F>(f), std::forward<Args>(args)...)));
        // Do something...
    }
    

    Ich versuche dann eine Task einzufügen:

    std::promise<void> promise_integration_done;
    std::promise<uint32_t> promise_image_buffer_id;
    std::promise<std::time_t> promise_image_acquired_time_stamp;
    // ...
    thread_pool.enqueue(std::bind(&image_based_linear_autofocus::capture_image,
    							this,
    							std::placeholders::_1,
    							std::placeholders::_2,
    							std::placeholders::_3),
    							std::move(promise_integration_done),
    							std::move(promise_image_buffer_id),
    							std::move(promise_image_acquired_time_stamp));
    

    Die Signatur von capture_image() sieht so aus:

    void capture_image(std::promise<void> integration_done_promise_caller,
                       std::promise<uint32_t> image_buffer_id_promise,
                       std::promise<std::time_t> image_acquired_time_stamp);
    

    Nun bekomme ich eine ziemlich hässliche Fehlermeldung:

    ====================[ Build | all | Debug ]=====================================
    /home/user/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/201.7223.86/bin/cmake/linux/bin/cmake --build /home/user/develop/umsa-ial-units-macsima/cmake-build-debug --target all -- -j 4
    [1/4] Building CXX object devices/autofocus-device/src/CMakeFiles/autofocus-device-object.dir/image_based_linear_autofocus.cpp.o
    FAILED: devices/autofocus-device/src/CMakeFiles/autofocus-device-object.dir/image_based_linear_autofocus.cpp.o 
    ccache /usr/bin/c++  -DBOOST_ALL_DYN_LINK -I../devices/autofocus-device/src/../include -I_deps/umsa-src/umsa-core/src/../include -I_deps/umsa-src/umsa-imaging/src/../include -I_deps/umsa-src/umsa-params/src/../include -I_deps/umsa-ial-src/umsa-ial-image_buffer/src/../include -I_deps/umsa-ial-src/umsa-ial-core/src/../include -I_deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core -I_deps/umsa-ial-src/umsa-ial-core/src/../src -I_deps/umsa-ial-src/umsa-ial-devices-core/src/../include -I_deps/umsa-src/umsa-object_storage/src/../include -isystem /usr/include/opencv -g -fPIC   --coverage -std=gnu++1z -MD -MT devices/autofocus-device/src/CMakeFiles/autofocus-device-object.dir/image_based_linear_autofocus.cpp.o -MF devices/autofocus-device/src/CMakeFiles/autofocus-device-object.dir/image_based_linear_autofocus.cpp.o.d -o devices/autofocus-device/src/CMakeFiles/autofocus-device-object.dir/image_based_linear_autofocus.cpp.o -c ../devices/autofocus-device/src/image_based_linear_autofocus.cpp
    In file included from _deps/umsa-src/umsa-core/src/../include/umsa/core/thread_pool.h:9:0,
                     from _deps/umsa-src/umsa-core/src/../include/umsa/core.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core/service_locator.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core.h:3,
                     from _deps/umsa-ial-src/umsa-ial-devices-core/src/../include/umsa/ial/devices/core/device.h:6,
                     from ../devices/autofocus-device/src/../include/autofocus/image_based_linear_autofocus.h:4,
                     from ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:1:
    /usr/include/c++/7/future: In instantiation of ‘struct std::__future_base::_Task_state<_Fn, _Alloc, _Res(_Args ...)>::_M_run(_Args&& ...) [with _Fn = std::_Bind<std::_Bind<void (umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::*(umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>; _Alloc = std::allocator<int>; _Res = void; _Args = {}]::<lambda>’:
    /usr/include/c++/7/future:1420:7:   required from ‘void std::__future_base::_Task_state<_Fn, _Alloc, _Res(_Args ...)>::_M_run(_Args&& ...) [with _Fn = std::_Bind<std::_Bind<void (umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::*(umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>; _Alloc = std::allocator<int>; _Res = void; _Args = {}]’
    ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:378:1:   required from here
    /usr/include/c++/7/future:1420:67: error: no type named ‘type’ in ‘class std::result_of<std::_Bind<std::_Bind<void (umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::*(umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>&()>’
      auto __boundfn = [&] () -> typename result_of<_Fn&(_Args&&...)>::type {
                                                                       ^~~~
    /usr/include/c++/7/future: In instantiation of ‘struct std::__future_base::_Task_state<_Fn, _Alloc, _Res(_Args ...)>::_M_run_delayed(_Args&& ..., std::weak_ptr<std::__future_base::_State_baseV2>) [with _Fn = std::_Bind<std::_Bind<void (umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::*(umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>; _Alloc = std::allocator<int>; _Res = void; _Args = {}]::<lambda>’:
    /usr/include/c++/7/future:1429:7:   required from ‘void std::__future_base::_Task_state<_Fn, _Alloc, _Res(_Args ...)>::_M_run_delayed(_Args&& ..., std::weak_ptr<std::__future_base::_State_baseV2>) [with _Fn = std::_Bind<std::_Bind<void (umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::*(umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>; _Alloc = std::allocator<int>; _Res = void; _Args = {}]’
    ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:378:1:   required from here
    /usr/include/c++/7/future:1429:67: error: no type named ‘type’ in ‘class std::result_of<std::_Bind<std::_Bind<void (umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::*(umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>&()>’
      auto __boundfn = [&] () -> typename result_of<_Fn&(_Args&&...)>::type {
                                                                       ^~~~
    /usr/include/c++/7/future:619:7: error: ‘static std::__future_base::_Task_setter<_Res_ptr, _BoundFn> std::__future_base::_S_task_setter(_Res_ptr&, _BoundFn&) [with _Res_ptr = std::unique_ptr<std::__future_base::_Result<void>, std::__future_base::_Result_base::_Deleter>; _BoundFn = std::__future_base::_Task_state<_Fn, _Alloc, _Res(_Args ...)>::_M_run(_Args&& ...) [with _Fn = std::_Bind<std::_Bind<void (umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::*(umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>; _Alloc = std::allocator<int>; _Res = void; _Args = {}]::<lambda>; typename _Res_ptr::element_type::result_type = void]’, declared using local type ‘std::__future_base::_Task_state<_Fn, _Alloc, _Res(_Args ...)>::_M_run(_Args&& ...) [with _Fn = std::_Bind<std::_Bind<void (umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::*(umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>; _Alloc = std::allocator<int>; _Res = void; _Args = {}]::<lambda>’, is used but never defined [-fpermissive]
           _S_task_setter(_Res_ptr& __ptr, _BoundFn& __call)
           ^~~~~~~~~~~~~~
    /usr/include/c++/7/future:619:7: error: ‘static std::__future_base::_Task_setter<_Res_ptr, _BoundFn> std::__future_base::_S_task_setter(_Res_ptr&, _BoundFn&) [with _Res_ptr = std::unique_ptr<std::__future_base::_Result<void>, std::__future_base::_Result_base::_Deleter>; _BoundFn = std::__future_base::_Task_state<_Fn, _Alloc, _Res(_Args ...)>::_M_run_delayed(_Args&& ..., std::weak_ptr<std::__future_base::_State_baseV2>) [with _Fn = std::_Bind<std::_Bind<void (umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::*(umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>; _Alloc = std::allocator<int>; _Res = void; _Args = {}]::<lambda>; typename _Res_ptr::element_type::result_type = void]’, declared using local type ‘std::__future_base::_Task_state<_Fn, _Alloc, _Res(_Args ...)>::_M_run_delayed(_Args&& ..., std::weak_ptr<std::__future_base::_State_baseV2>) [with _Fn = std::_Bind<std::_Bind<void (umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::*(umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)>; _Alloc = std::allocator<int>; _Res = void; _Args = {}]::<lambda>’, is used but never defined [-fpermissive]
    /usr/include/c++/7/future:619: confused by earlier errors, bailing out
    ninja: build stopped: subcommand failed.
    

    Die Fehlermeldung sagt mir leider nicht viel.
    Würde ich image_capture() direkt aufrufen ohne thread_pool.enqueue() funktioniert das.

    Weiß jemand weiter?

    Danke im Voraus!



  • Benutze Lambda, nicht std::bind.



  • @manni66 sagte in std::bind() mit Parameter-Übergabe:

    Benutze Lambda, nicht std::bind.

    Das Problem ist, dass die promisses auf dem Stack innerhalb einer Schleife liegen. Ich muss die promisses also irgendwie rein-moven und da bekomme ich ebenfalls einen Fehler.

    for ()
    {
    	std::promise<void> promise_integration_done;
    	std::promise<uint32_t> promise_image_buffer_id;
    	std::promise<std::time_t> promise_image_acquired_time_stamp;
    
    	// ...
    
    	auto bla = [&,
    				p1{std::move(promise_integration_done)},
    				p2{std::move(promise_image_buffer_id)},
    				p3{std::move(promise_image_acquired_time_stamp)}]()
    	{
    		capture_image(std::move(p1),
    					  std::move(p2),
    					  std::move(p3));
    	};
    
    	thread_pool.enqueue(bla);
    }
    
    ====================[ Build | all | Debug ]=====================================
    /home/user/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/201.7223.86/bin/cmake/linux/bin/cmake --build /home/user/develop/umsa-ial-units-macsima/cmake-build-debug --target all -- -j 4
    [1/4] Building CXX object devices/autofocus-device/src/CMakeFiles/autofocus-device-object.dir/image_based_linear_autofocus.cpp.o
    FAILED: devices/autofocus-device/src/CMakeFiles/autofocus-device-object.dir/image_based_linear_autofocus.cpp.o 
    ccache /usr/bin/c++  -DBOOST_ALL_DYN_LINK -I../devices/autofocus-device/src/../include -I_deps/umsa-src/umsa-core/src/../include -I_deps/umsa-src/umsa-imaging/src/../include -I_deps/umsa-src/umsa-params/src/../include -I_deps/umsa-ial-src/umsa-ial-image_buffer/src/../include -I_deps/umsa-ial-src/umsa-ial-core/src/../include -I_deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core -I_deps/umsa-ial-src/umsa-ial-core/src/../src -I_deps/umsa-ial-src/umsa-ial-devices-core/src/../include -I_deps/umsa-src/umsa-object_storage/src/../include -isystem /usr/include/opencv -g -fPIC   --coverage -std=gnu++1z -MD -MT devices/autofocus-device/src/CMakeFiles/autofocus-device-object.dir/image_based_linear_autofocus.cpp.o -MF devices/autofocus-device/src/CMakeFiles/autofocus-device-object.dir/image_based_linear_autofocus.cpp.o.d -o devices/autofocus-device/src/CMakeFiles/autofocus-device-object.dir/image_based_linear_autofocus.cpp.o -c ../devices/autofocus-device/src/image_based_linear_autofocus.cpp
    ../devices/autofocus-device/src/image_based_linear_autofocus.cpp: In lambda function:
    ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:166:48: error: use of deleted function ‘std::promise<void>::promise(const std::promise<void>&)’
                                       std::move(p3));
                                                    ^
    In file included from _deps/umsa-src/umsa-core/src/../include/umsa/core/thread_pool.h:9:0,
                     from _deps/umsa-src/umsa-core/src/../include/umsa/core.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core/service_locator.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core.h:3,
                     from _deps/umsa-ial-src/umsa-ial-devices-core/src/../include/umsa/ial/devices/core/device.h:6,
                     from ../devices/autofocus-device/src/../include/autofocus/image_based_linear_autofocus.h:4,
                     from ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:1:
    /usr/include/c++/7/future:1280:7: note: declared here
           promise(const promise&) = delete;
           ^~~~~~~
    In file included from ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:1:0:
    ../devices/autofocus-device/src/../include/autofocus/image_based_linear_autofocus.h:34:10: note:   initializing argument 1 of ‘void umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::capture_image(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)’
         void capture_image(std::promise<void> integration_done_promise_caller,
              ^~~~~~~~~~~~~
    ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:166:48: error: use of deleted function ‘std::promise<_Res>::promise(const std::promise<_Res>&) [with _Res = unsigned int]’
                                       std::move(p3));
                                                    ^
    In file included from _deps/umsa-src/umsa-core/src/../include/umsa/core/thread_pool.h:9:0,
                     from _deps/umsa-src/umsa-core/src/../include/umsa/core.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core/service_locator.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core.h:3,
                     from _deps/umsa-ial-src/umsa-ial-devices-core/src/../include/umsa/ial/devices/core/device.h:6,
                     from ../devices/autofocus-device/src/../include/autofocus/image_based_linear_autofocus.h:4,
                     from ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:1:
    /usr/include/c++/7/future:1077:7: note: declared here
           promise(const promise&) = delete;
           ^~~~~~~
    In file included from ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:1:0:
    ../devices/autofocus-device/src/../include/autofocus/image_based_linear_autofocus.h:34:10: note:   initializing argument 2 of ‘void umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::capture_image(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)’
         void capture_image(std::promise<void> integration_done_promise_caller,
              ^~~~~~~~~~~~~
    ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:166:48: error: use of deleted function ‘std::promise<_Res>::promise(const std::promise<_Res>&) [with _Res = long int]’
                                       std::move(p3));
                                                    ^
    In file included from _deps/umsa-src/umsa-core/src/../include/umsa/core/thread_pool.h:9:0,
                     from _deps/umsa-src/umsa-core/src/../include/umsa/core.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core/service_locator.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core.h:3,
                     from _deps/umsa-ial-src/umsa-ial-devices-core/src/../include/umsa/ial/devices/core/device.h:6,
                     from ../devices/autofocus-device/src/../include/autofocus/image_based_linear_autofocus.h:4,
                     from ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:1:
    /usr/include/c++/7/future:1077:7: note: declared here
           promise(const promise&) = delete;
           ^~~~~~~
    In file included from ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:1:0:
    ../devices/autofocus-device/src/../include/autofocus/image_based_linear_autofocus.h:34:10: note:   initializing argument 3 of ‘void umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::capture_image(std::promise<void>, std::promise<unsigned int>, std::promise<long int>)’
         void capture_image(std::promise<void> integration_done_promise_caller,
              ^~~~~~~~~~~~~
    In file included from /usr/include/boost/property_tree/ptree_fwd.hpp:17:0,
                     from /usr/include/boost/property_tree/ptree.hpp:15,
                     from _deps/umsa-ial-src/umsa-ial-devices-core/src/../include/umsa/ial/devices/core/interfaces/autofocus/autofocus_parameters.h:5,
                     from ../devices/autofocus-device/src/../include/autofocus/linear_autofocus_setup.h:3,
                     from ../devices/autofocus-device/src/../include/autofocus/image_based_linear_autofocus.h:3,
                     from ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:1:
    /usr/include/c++/7/functional: In instantiation of ‘std::_Bind<_Functor(_Bound_args ...)>::_Bind(const _Functor&, _Args&& ...) [with _Args = {}; _Functor = umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::do_autofocus(const std::shared_ptr<umsa::ial::devices::core::interfaces::autofocus::autofocus_parameters>&)::<lambda()>::<lambda()>; _Bound_args = {}]’:
    /usr/include/c++/7/functional:878:38:   required from ‘typename std::_Bind_helper<std::__is_socketlike<_Func>::value, _Func, _BoundArgs ...>::type std::bind(_Func&&, _BoundArgs&& ...) [with _Func = umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::do_autofocus(const std::shared_ptr<umsa::ial::devices::core::interfaces::autofocus::autofocus_parameters>&)::<lambda()>::<lambda()>&; _BoundArgs = {}; typename std::_Bind_helper<std::__is_socketlike<_Func>::value, _Func, _BoundArgs ...>::type = std::_Bind<umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::do_autofocus(const std::shared_ptr<umsa::ial::devices::core::interfaces::autofocus::autofocus_parameters>&)::<lambda()>::<lambda()>()>]’
    _deps/umsa-src/umsa-core/src/../include/umsa/core/thread_pool.h:80:38:   required from ‘std::shared_future<typename std::result_of<_Functor(_ArgTypes ...)>::type> umsa::core::thread_pool::enqueue(F&&, Args&& ...) [with F = umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::do_autofocus(const std::shared_ptr<umsa::ial::devices::core::interfaces::autofocus::autofocus_parameters>&)::<lambda()>::<lambda()>&; Args = {}; typename std::result_of<_Functor(_ArgTypes ...)>::type = void]’
    ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:169:40:   required from here
    /usr/include/c++/7/functional:529:59: error: use of deleted function ‘umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::do_autofocus(const std::shared_ptr<umsa::ial::devices::core::interfaces::autofocus::autofocus_parameters>&)::<lambda()>::<lambda()>::<lambda>(const umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::do_autofocus(const std::shared_ptr<umsa::ial::devices::core::interfaces::autofocus::autofocus_parameters>&)::<lambda()>::<lambda()>&)’
      : _M_f(__f), _M_bound_args(std::forward<_Args>(__args)...)
                                                               ^
    ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:162:77: note: ‘umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::do_autofocus(const std::shared_ptr<umsa::ial::devices::core::interfaces::autofocus::autofocus_parameters>&)::<lambda()>::<lambda()>::<lambda>(const umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::do_autofocus(const std::shared_ptr<umsa::ial::devices::core::interfaces::autofocus::autofocus_parameters>&)::<lambda()>::<lambda()>&)’ is implicitly deleted because the default definition would be ill-formed:
                                 p3{std::move(promise_image_acquired_time_stamp)}]()
                                                                                 ^
    ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:162:77: error: use of deleted function ‘std::promise<void>::promise(const std::promise<void>&)’
    In file included from _deps/umsa-src/umsa-core/src/../include/umsa/core/thread_pool.h:9:0,
                     from _deps/umsa-src/umsa-core/src/../include/umsa/core.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core/service_locator.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core.h:3,
                     from _deps/umsa-ial-src/umsa-ial-devices-core/src/../include/umsa/ial/devices/core/device.h:6,
                     from ../devices/autofocus-device/src/../include/autofocus/image_based_linear_autofocus.h:4,
                     from ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:1:
    /usr/include/c++/7/future:1280:7: note: declared here
           promise(const promise&) = delete;
           ^~~~~~~
    ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:162:77: error: use of deleted function ‘std::promise<_Res>::promise(const std::promise<_Res>&) [with _Res = unsigned int]’
                                 p3{std::move(promise_image_acquired_time_stamp)}]()
                                                                                 ^
    In file included from _deps/umsa-src/umsa-core/src/../include/umsa/core/thread_pool.h:9:0,
                     from _deps/umsa-src/umsa-core/src/../include/umsa/core.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core/service_locator.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core.h:3,
                     from _deps/umsa-ial-src/umsa-ial-devices-core/src/../include/umsa/ial/devices/core/device.h:6,
                     from ../devices/autofocus-device/src/../include/autofocus/image_based_linear_autofocus.h:4,
                     from ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:1:
    /usr/include/c++/7/future:1077:7: note: declared here
           promise(const promise&) = delete;
           ^~~~~~~
    ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:162:77: error: use of deleted function ‘std::promise<_Res>::promise(const std::promise<_Res>&) [with _Res = long int]’
                                 p3{std::move(promise_image_acquired_time_stamp)}]()
                                                                                 ^
    In file included from _deps/umsa-src/umsa-core/src/../include/umsa/core/thread_pool.h:9:0,
                     from _deps/umsa-src/umsa-core/src/../include/umsa/core.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core/service_locator.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core.h:3,
                     from _deps/umsa-ial-src/umsa-ial-devices-core/src/../include/umsa/ial/devices/core/device.h:6,
                     from ../devices/autofocus-device/src/../include/autofocus/image_based_linear_autofocus.h:4,
                     from ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:1:
    /usr/include/c++/7/future:1077:7: note: declared here
           promise(const promise&) = delete;
           ^~~~~~~
    ninja: build stopped: subcommand failed.
    
    


  • Warum movest du nicht direkt promise_integration_done usw. innerhalb der Lambdafunktion? Ansonsten müsste es wohl ein mutable Lambda sein.



  • @manni66 sagte in std::bind() mit Parameter-Übergabe:

    Warum movest du nicht direkt promise_integration_done usw. innerhalb der Lambdafunktion? Ansonsten müsste es wohl ein mutable Lambda sein.

    Du meinst so?

    for ()
    {
    	std::promise<void> promise_integration_done;
    	std::promise<uint32_t> promise_image_buffer_id;
    	std::promise<std::time_t> promise_image_acquired_time_stamp;
    
    	// ...
    
    	auto bla = [&]()
    	{
    		capture_image(std::move(promise_integration_done),
    					  std::move(promise_image_buffer_id),
    					  std::move(promise_image_acquired_time_stamp));
    	};
    
    	thread_pool.enqueue(bla);
    }
    

    Was ist mit der Lebenszeit der Promises? Ich weiß ja nicht, wann das Lamda ausgeführt wird, da es in einem Thread-Pool hinzugefügt wird.
    Die For-Schleife könnte schon bei der nächsten Iteration sein, bevor die Promisses gemovet werden.



  • @Steffo sagte in std::bind() mit Parameter-Übergabe:

    Was ist mit der Lebenszeit der Promises? Ich weiß ja nicht, wann das Lamda ausgeführt wird, da es in einem Thread-Pool hinzugefügt wird.
    Die For-Schleife könnte schon bei der nächsten Iteration sein, bevor die Promisses gemovet werden.

    Stimmt, dann muss das Lambda mutable sein.



  • @manni66
    So langsam bin mich mit meinem Latein am Ende...

    for (...)
    {
    	std::promise<void> promise_integration_done;
    	std::promise<uint32_t> promise_image_buffer_id;
    	std::promise<std::time_t> promise_image_acquired_time_stamp;
    
    	// ...
    
    	auto bla = [&,
    				p1{std::move(promise_integration_done)},
    				p2{std::move(promise_image_buffer_id)},
    				p3{std::move(promise_image_acquired_time_stamp)}]() mutable
    	{
    		capture_image(std::move(p1),
    					  std::move(p2),
    					  std::move(p3));
    	};
    
    	thread_pool.enqueue(bla);
    }
    
    ====================[ Build | all | Debug ]=====================================
    /home/user/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/201.7223.86/bin/cmake/linux/bin/cmake --build /home/user/develop/umsa-ial-units-macsima/cmake-build-debug --target all -- -j 4
    [1/4] Building CXX object devices/autofocus-device/src/CMakeFiles/autofocus-device-object.dir/image_based_linear_autofocus.cpp.o
    FAILED: devices/autofocus-device/src/CMakeFiles/autofocus-device-object.dir/image_based_linear_autofocus.cpp.o 
    ccache /usr/bin/c++  -DBOOST_ALL_DYN_LINK -I../devices/autofocus-device/src/../include -I_deps/umsa-src/umsa-core/src/../include -I_deps/umsa-src/umsa-imaging/src/../include -I_deps/umsa-src/umsa-params/src/../include -I_deps/umsa-ial-src/umsa-ial-image_buffer/src/../include -I_deps/umsa-ial-src/umsa-ial-core/src/../include -I_deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core -I_deps/umsa-ial-src/umsa-ial-core/src/../src -I_deps/umsa-ial-src/umsa-ial-devices-core/src/../include -I_deps/umsa-src/umsa-object_storage/src/../include -isystem /usr/include/opencv -g -fPIC   --coverage -std=gnu++1z -MD -MT devices/autofocus-device/src/CMakeFiles/autofocus-device-object.dir/image_based_linear_autofocus.cpp.o -MF devices/autofocus-device/src/CMakeFiles/autofocus-device-object.dir/image_based_linear_autofocus.cpp.o.d -o devices/autofocus-device/src/CMakeFiles/autofocus-device-object.dir/image_based_linear_autofocus.cpp.o -c ../devices/autofocus-device/src/image_based_linear_autofocus.cpp
    In file included from /usr/include/boost/property_tree/ptree_fwd.hpp:17:0,
                     from /usr/include/boost/property_tree/ptree.hpp:15,
                     from _deps/umsa-ial-src/umsa-ial-devices-core/src/../include/umsa/ial/devices/core/interfaces/autofocus/autofocus_parameters.h:5,
                     from ../devices/autofocus-device/src/../include/autofocus/linear_autofocus_setup.h:3,
                     from ../devices/autofocus-device/src/../include/autofocus/image_based_linear_autofocus.h:3,
                     from ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:1:
    /usr/include/c++/7/functional: In instantiation of ‘std::_Bind<_Functor(_Bound_args ...)>::_Bind(const _Functor&, _Args&& ...) [with _Args = {}; _Functor = umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::do_autofocus(const std::shared_ptr<umsa::ial::devices::core::interfaces::autofocus::autofocus_parameters>&)::<lambda()>::<lambda()>; _Bound_args = {}]’:
    /usr/include/c++/7/functional:878:38:   required from ‘typename std::_Bind_helper<std::__is_socketlike<_Func>::value, _Func, _BoundArgs ...>::type std::bind(_Func&&, _BoundArgs&& ...) [with _Func = umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::do_autofocus(const std::shared_ptr<umsa::ial::devices::core::interfaces::autofocus::autofocus_parameters>&)::<lambda()>::<lambda()>&; _BoundArgs = {}; typename std::_Bind_helper<std::__is_socketlike<_Func>::value, _Func, _BoundArgs ...>::type = std::_Bind<umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::do_autofocus(const std::shared_ptr<umsa::ial::devices::core::interfaces::autofocus::autofocus_parameters>&)::<lambda()>::<lambda()>()>]’
    _deps/umsa-src/umsa-core/src/../include/umsa/core/thread_pool.h:80:38:   required from ‘std::shared_future<typename std::result_of<_Functor(_ArgTypes ...)>::type> umsa::core::thread_pool::enqueue(F&&, Args&& ...) [with F = umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::do_autofocus(const std::shared_ptr<umsa::ial::devices::core::interfaces::autofocus::autofocus_parameters>&)::<lambda()>::<lambda()>&; Args = {}; typename std::result_of<_Functor(_ArgTypes ...)>::type = void]’
    ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:169:40:   required from here
    /usr/include/c++/7/functional:529:59: error: use of deleted function ‘umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::do_autofocus(const std::shared_ptr<umsa::ial::devices::core::interfaces::autofocus::autofocus_parameters>&)::<lambda()>::<lambda()>::<lambda>(const umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::do_autofocus(const std::shared_ptr<umsa::ial::devices::core::interfaces::autofocus::autofocus_parameters>&)::<lambda()>::<lambda()>&)’
      : _M_f(__f), _M_bound_args(std::forward<_Args>(__args)...)
                                                               ^
    ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:162:77: note: ‘umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::do_autofocus(const std::shared_ptr<umsa::ial::devices::core::interfaces::autofocus::autofocus_parameters>&)::<lambda()>::<lambda()>::<lambda>(const umsa::ial::devices::macsima::autofocus::image_based_linear_autofocus::do_autofocus(const std::shared_ptr<umsa::ial::devices::core::interfaces::autofocus::autofocus_parameters>&)::<lambda()>::<lambda()>&)’ is implicitly deleted because the default definition would be ill-formed:
                                 p3{std::move(promise_image_acquired_time_stamp)}]() mutable
                                                                                 ^
    ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:162:77: error: use of deleted function ‘std::promise<void>::promise(const std::promise<void>&)’
    In file included from _deps/umsa-src/umsa-core/src/../include/umsa/core/thread_pool.h:9:0,
                     from _deps/umsa-src/umsa-core/src/../include/umsa/core.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core/service_locator.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core.h:3,
                     from _deps/umsa-ial-src/umsa-ial-devices-core/src/../include/umsa/ial/devices/core/device.h:6,
                     from ../devices/autofocus-device/src/../include/autofocus/image_based_linear_autofocus.h:4,
                     from ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:1:
    /usr/include/c++/7/future:1280:7: note: declared here
           promise(const promise&) = delete;
           ^~~~~~~
    ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:162:77: error: use of deleted function ‘std::promise<_Res>::promise(const std::promise<_Res>&) [with _Res = unsigned int]’
                                 p3{std::move(promise_image_acquired_time_stamp)}]() mutable
                                                                                 ^
    In file included from _deps/umsa-src/umsa-core/src/../include/umsa/core/thread_pool.h:9:0,
                     from _deps/umsa-src/umsa-core/src/../include/umsa/core.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core/service_locator.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core.h:3,
                     from _deps/umsa-ial-src/umsa-ial-devices-core/src/../include/umsa/ial/devices/core/device.h:6,
                     from ../devices/autofocus-device/src/../include/autofocus/image_based_linear_autofocus.h:4,
                     from ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:1:
    /usr/include/c++/7/future:1077:7: note: declared here
           promise(const promise&) = delete;
           ^~~~~~~
    ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:162:77: error: use of deleted function ‘std::promise<_Res>::promise(const std::promise<_Res>&) [with _Res = long int]’
                                 p3{std::move(promise_image_acquired_time_stamp)}]() mutable
                                                                                 ^
    In file included from _deps/umsa-src/umsa-core/src/../include/umsa/core/thread_pool.h:9:0,
                     from _deps/umsa-src/umsa-core/src/../include/umsa/core.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core/service_locator.h:5,
                     from _deps/umsa-ial-src/umsa-ial-core/src/../include/umsa/ial/core.h:3,
                     from _deps/umsa-ial-src/umsa-ial-devices-core/src/../include/umsa/ial/devices/core/device.h:6,
                     from ../devices/autofocus-device/src/../include/autofocus/image_based_linear_autofocus.h:4,
                     from ../devices/autofocus-device/src/image_based_linear_autofocus.cpp:1:
    /usr/include/c++/7/future:1077:7: note: declared here
           promise(const promise&) = delete;
           ^~~~~~~
    ninja: build stopped: subcommand failed.
    
    

    Ich werde das wohl ganz anders lösen.



  • Kompiliert es denn ohne Aufruf von capture_image?

    Und bzgl. der Fehlermeldung

    promise(const promise&) = delete;

    std::promise hat keinen Copy-Constructor, daher paßt die Signatur von capture_image bzgl. der Parameter nicht (nimm dort mal && je Parameter).

    Edit: Evtl. probiere mal explizit &p1{std::move(promise_integration_done)} etc. bzw. verschiebe die drei std::promise-Variablen innerhalb des Lambda-Ausdrucks.



  • Sorry, für die Umstände. Ich versuche meinen Code zu vereinfachen und es anders zu lösen.
    Dennoch danke für eure Antworten!


Log in to reply