#include #include #ifdef CHAISCRIPT_NO_DYNLOAD #include #endif #include #include int expected_value(int num_iters) { int i = 0; for (int k = 0; k usepaths; usepaths.push_back(""); if (usepath) { usepaths.push_back(usepath); } std::vector modulepaths; #ifdef CHAISCRIPT_NO_DYNLOAD chaiscript::ChaiScript chai(/* unused */modulepaths, usepaths); #else modulepaths.push_back(""); if (modulepath) { modulepaths.push_back(modulepath); } // For this test we are going to load the dynamic stdlib // to make sure it continues to work chaiscript::ChaiScript_Basic chai( std::make_unique>(), modulepaths,usepaths); #endif std::vector > threads; // Ensure at least two, but say only 7 on an 8 core processor size_t num_threads = static_cast(std::max(static_cast(std::thread::hardware_concurrency()) - 1, 2)); std::cout << "Num threads: " << num_threads << '\n'; for (size_t i = 0; i < num_threads; ++i) { threads.push_back(std::make_shared(do_work, std::ref(chai), i)); } for (size_t i = 0; i < num_threads; ++i) { threads[i]->join(); } for (size_t i = 0; i < num_threads; ++i) { std::stringstream ss; ss << i; if (chai.eval("getvalue(" + ss.str() + ")") != expected_value(4000)) { return EXIT_FAILURE; } if (chai.eval("getid(" + ss.str() + ")") != static_cast(i)) { return EXIT_FAILURE; } } return EXIT_SUCCESS; }