0

I'm trying to use C++ executor. This is the code I found in https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p0443r14.html. It should be supported by gcc 11.

I compiled this code with command

g++-11 main.cpp -ltbb
#include <iostream>
#include <execution>
using namespace std::execution;

int main() {
  std::static_thread_pool pool(16);
  executor auto ex = pool.executor();
  perform_business_logic(ex);
  execute(ex, []{ std::cout << "Hello world from the thread pool!"; });
}

It gives a lot of errors.

error: ‘thread_pool’ is not a member of ‘std’
error: ‘executor’ was not declared in this scope
error: ‘ex’ was not declared in this scope
user17732522
  • 53,019
  • 2
  • 56
  • 105

1 Answers1

3

This is just a proposal for addition to the C++ standard. It was never adopted.

See https://github.com/cplusplus/papers/issues/102 regarding the progress of this proposal which was closed and https://github.com/cplusplus/papers/issues/1054 for the executor proposal which is currently still under consideration for C++26.

Currently there is no equivalent in any C++ revision (published or drafting). It is unlikely that you will find a compiler/standard library supporting any of the proposals except maybe as experimental implementations for demonstration. In particular I am not sure what you base "It should be supported by gcc 11." on. (The original C++17 tag on the question also doesn't make sense, since the linked proposal is from 2020.)

user17732522
  • 53,019
  • 2
  • 56
  • 105
  • There is a question about the 2017 execution policy https://stackoverflow.com/questions/51031060/are-c17-parallel-algorithms-implemented-already so I thought it might be 2017. I have no idea how they propose things. Thanks. – Tianyi Xie Jun 08 '22 at 15:04
  • @TianyiXie Then you got things mixed up. That's a different addition to the language. It was proposed in https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0024r2.html and adopted for C++17. See the block about execution policies at https://en.cppreference.com/w/cpp/algorithm for an up-to-date reference. And yes, that should be supported by GCC 11 with TBB. – user17732522 Jun 08 '22 at 18:02