I'd like to use thread_pool as a static struct/class member, for a test demo code like
//bs_thread_pool.cpp
#include <algorithm> // std::min, std::min_element, std::sort, std::unique
#include <atomic> // std::atomic
#include <chrono> // std::chrono
#include <cmath> // std::abs, std::llround, std::round, std::sqrt
#include <ctime> // std::localtime, std::strftime, std::time_t
#include <exception> // std::exception
#include <fstream> // std::ofstream
#include <future> // std::future
#include <iomanip> // std::setprecision, std::setw
#include <ios> // std::fixed
#include <iostream> // std::cout
#include <limits> // std::numeric_limits
#include <random> // std::mt19937_64, std::random_device, std::uniform_int_distribution, std::uniform_real_distribution
#include <stdexcept> // std::runtime_error
#include <string> // std::string, std::to_string
#include <thread> // std::this_thread, std::thread
#include <utility> // std::pair
#include <vector> // std::begin, std::end, std::vector
// Include the header file for the thread pool library.
#include "BS_thread_pool.hpp"
struct test{
static BS::thread_pool pool;
static void testfunc(){
int squares[100];
pool.parallelize_loop(0, 100,
[&squares](const int a, const int b)
{
for (int i = a; i < b; ++i)
squares[i] = i * i;
})
.wait();
}
};
int main(){
test::testfunc();
return 0;
}
/tmp/cc6he5hB.o: In function `test::testfunc()':
bs_thread_pool.cpp:(.text._ZN4test8testfuncEv[_ZN4test8testfuncEv]+0x3f): undefined reference to `test::pool'
collect2: error: ld returned 1 exit status