samedi 5 octobre 2019

Passing shared_ptr as an argument to thread function, results into an error

I am trying to do something similar as below:

std::shared_ptr<asengine::PreCompileConfig> precompileconfigobj = std::make_shared<asengine::PreCompileConfig>();

std::thread rsync_t(&asengine::PreCompile::RunRsyncDb, precompileconfigobj));

I get the following error:

/usr/include/c++/4.8/functional:1697:61: error: no type named 'type' in 'class std::result_of<std::_Mem_fn<void (asengine::PreCompile::*)(const std::shared_ptr<asengine::PreCompileConfig>&)>(std::reference_wrapper<std::shared_ptr<asengine::PreCompileConfig> >)>'
   typedef typename result_of<_Callable(_Args...)>::type result_type;
                                                         ^
/usr/include/c++/4.8/functional:1727:9: error: no type named 'type' in 'class std::result_of<std::_Mem_fn<void (asengine::PreCompile::*)(const std::shared_ptr<asengine::PreCompileConfig>&)>(std::reference_wrapper<std::shared_ptr<asengine::PreCompileConfig> >)>'
     _M_invoke(_Index_tuple<_Indices...>)

After brief research, I could find out that thread function expects reference of the argument object, instead of value.

std::thread rsync_t(&asengine::PreCompile::RunRsyncDb, std::ref(precompileconfigobj));

But still, it doesn't solve the problem. Any help to figure out the problem would be appreciated.

Aucun commentaire:

Enregistrer un commentaire