0

I've read this article about multi-core processing:
https://blogs.msdn.microsoft.com/usisvde/2009/10/24/how-to-get-started-with-multi-core-parallel-processing-you-can-use/

In .NET Framework 4 there is a method called System.Threading.Tasks that can manage the available logical processors. Is there any way to do quite the same in C++ and UNIX without .NET Framework ?

By the same I mean avoid the overheard of the threads.

Quentin
  • 31
  • 7

2 Answers2

1

No, there’s no built-in direct equivalent.

std::async launches a new thread for every asynchronous task, i.e. very slow when you have many short operations.

You can look for third-party C++ thread pool implementation.

Or you can switch to some higher-level API. I have positive experience with OpenMP, it’s included in most C++ compilers, and under the hood it does have a thread pool with a scheduler. I’ve heard Intel’s TBB is also good.

Soonts
  • 20,079
  • 9
  • 57
  • 130
0

Not sure exactly what the .NET does but std::async / std::future allows parallel queuing of tasks.

doron
  • 27,972
  • 12
  • 65
  • 103
  • Oh, very interesting! I think you're right, it seems that `std::async` is based in some way on `std::thread::hardware_concurrency`. Thank you for this quick answer! – Quentin Dec 02 '17 at 09:28