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

Problem with std::packaged_task #83

Open
Jamaika1 opened this issue Apr 18, 2021 · 2 comments
Open

Problem with std::packaged_task #83

Jamaika1 opened this issue Apr 18, 2021 · 2 comments

Comments

@Jamaika1
Copy link

Jamaika1 commented Apr 18, 2021

I use GCC 11 with library mingw.
https://github.com/meganz/mingw-std-threads

In file included from c:\msys1101\include\c++\11.0.1\unordered_map:42,
                 from c:\msys1101\include\c++\11.0.1\functional:61,
                 from c:\msys1101\include\c++\11.0.1\pstl\glue_algorithm_defs.h:13,
                 from c:\msys1101\include\c++\11.0.1\algorithm:74,
                 from grk_includes.h:42,
                 from CodeStreamCompress.cpp:22:
c:\msys1101\include\c++\11.0.1\ext\aligned_buffer.h: In instantiation of 'struct __gnu_cxx::__aligned_buffer<std::packaged_task<int()> >':
c:\msys1101\include\c++\11.0.1\bits\shared_ptr_base.h:506:35:   required from 'class std::_Sp_counted_ptr_inplace<std::packaged_task<int()>, std::allocator<std::packaged_task<int()> >, __gnu_cxx::_S_atomic>::_Impl'
c:\msys1101\include\c++\11.0.1\bits\shared_ptr_base.h:567:13:   required from 'class std::_Sp_counted_ptr_inplace<std::packaged_task<int()>, std::allocator<std::packaged_task<int()> >, __gnu_cxx::_S_atomic>'
c:\msys1101\include\c++\11.0.1\bits\shared_ptr_base.h:647:43:   required from 'std::__shared_count<_Lp>::__shared_count(_Tp*&, std::_Sp_alloc_shared_tag<_Alloc>, _Args&& ...) [with _Tp = std::packaged_task<int()>; _Alloc = std::allocator<std::packaged_task<int()> >; _Args = {std::_Bind<grk::CodeStreamCompress::compress(grk_plugin_tile*)::<lambda()>()>}; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]'
c:\msys1101\include\c++\11.0.1\bits\shared_ptr_base.h:1337:14:   required from 'std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<std::packaged_task<int()> >; _Args = {std::_Bind<grk::CodeStreamCompress::compress(grk_plugin_tile*)::<lambda()>()>}; _Tp = std::packaged_task<int()>; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]'
c:\msys1101\include\c++\11.0.1\bits\shared_ptr.h:409:59:   required from 'std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<std::packaged_task<int()> >; _Args = {std::_Bind<grk::CodeStreamCompress::compress(grk_plugin_tile*)::<lambda()>()>}; _Tp = std::packaged_task<int()>]'
c:\msys1101\include\c++\11.0.1\bits\shared_ptr.h:860:14:   required from 'std::shared_ptr<_Tp> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = std::packaged_task<int()>; _Alloc = std::allocator<std::packaged_task<int()> >; _Args = {std::_Bind<grk::CodeStreamCompress::compress(grk_plugin_tile*)::<lambda()>()>}]'
c:\msys1101\include\c++\11.0.1\bits\shared_ptr.h:876:39:   required from 'std::shared_ptr<_Tp> std::make_shared(_Args&& ...) [with _Tp = std::packaged_task<int()>; _Args = {std::_Bind<grk::CodeStreamCompress::compress(grk_plugin_tile*)::<lambda()>()>}]'
ThreadPool.hpp:174:65:   required from 'std::future<typename std::result_of<_Functor(_ArgTypes ...)>::type> ThreadPool::enqueue(F&&, Args&& ...) [with F = grk::CodeStreamCompress::compress(grk_plugin_tile*)::<lambda()>; Args = {}; typename std::result_of<_Functor(_ArgTypes ...)>::type = int]'
CodeStreamCompress.cpp:639:37:   required from here
c:\msys1101\include\c++\11.0.1\ext\aligned_buffer.h:91:28: error: invalid application of 'sizeof' to incomplete type 'std::packaged_task<int()>'
   91 |     : std::aligned_storage<sizeof(_Tp), __alignof__(_Tp)>
      |                            ^~~~~~~~~~~
c:\msys1101\include\c++\11.0.1\ext\aligned_buffer.h:91:28: error: invalid application of 'sizeof' to incomplete type 'std::packaged_task<int()>'
@wilx
Copy link
Contributor

wilx commented Apr 18, 2021

This is unlikely to be problem in ThreadPool. It properly includes <future>.

@Jamaika1
Copy link
Author

That's right. I have a problem with functions under C++17 in mingw.future.h.
meganz/mingw-std-threads#75

/*#if (__cplusplus < 201703L)
std::future<std::result_of<std::decay<Function>::type(std::decay<Args>::type...)>::type>
#else
#if (__cplusplus > 201703L)
[[nodiscard]]
#endif
std::future<std::invoke_result_t<std::decay_t<Function>, std::decay_t<Args>...>>
#endif*/
#if (__cplusplus > 201703L)
[[nodiscard]]
#endif
std::future<__async_result_of<Function, Args...> >
  async(Function&& f, Args&&... args)
{
  return async(launch::async | launch::deferred, std::forward<Function>(f), std::forward<Args>(args)...);
}
template< class Function, class... Args >
/*#if (__cplusplus < 201703L)
std::future<std::result_of<std::decay<Function>::type(std::decay<Args>::type...)>::type>
#else
#if (__cplusplus > 201703L)
[[nodiscard]]
#endif
std::future<std::invoke_result_t<std::decay_t<Function>, std::decay_t<Args>...> >
#endif*/
#if (__cplusplus > 201703L)
[[nodiscard]]
#endif
std::future<__async_result_of<Function, Args...> >
  async(std::launch policy, Function&& f, Args&&... args)
{
  typedef __async_result_of<Function, Args...> result_type;
/*#if (__cplusplus < 201703L)
  typedef std::result_of<std::decay<Function>::type(std::decay<Args>::type...)>::type result_type;
#else
  typedef std::invoke_result_t<std::decay_t<Function>, std::decay_t<Args>...> result_type;
#endif*/
  typedef future<result_type> future_type;
  typedef typename future_type::state_type state_type;

  //auto setter = []

  state_type * state_ptr = nullptr;
  /*if ((policy & std::launch::async) == std::launch::async)
    state_ptr = new state_type ();
  else
    state_ptr = new state_type (std::function<result_type(void)>(std::bind(std::forward<Function>(f), std::forward<Args>(args)...)));*/ 

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

2 participants