| 35 | } |
| 36 | |
| 37 | int main() |
| 38 | { |
| 39 | // Disable deprecation warning for getenv call. |
| 40 | #ifdef CHAISCRIPT_MSVC |
| 41 | #ifdef max // Why Microsoft? why? |
| 42 | #undef max |
| 43 | #endif |
| 44 | #pragma warning(push) |
| 45 | #pragma warning(disable : 4996) |
| 46 | #endif |
| 47 | |
| 48 | const char *usepath = getenv("CHAI_USE_PATH"); |
| 49 | const char *modulepath = getenv("CHAI_MODULE_PATH"); |
| 50 | |
| 51 | #ifdef CHAISCRIPT_MSVC |
| 52 | #pragma warning(pop) |
| 53 | #endif |
| 54 | |
| 55 | std::vector<std::string> usepaths; |
| 56 | usepaths.push_back(""); |
| 57 | if (usepath) |
| 58 | { |
| 59 | usepaths.push_back(usepath); |
| 60 | } |
| 61 | |
| 62 | std::vector<std::string> modulepaths; |
| 63 | |
| 64 | #ifdef CHAISCRIPT_NO_DYNLOAD |
| 65 | chaiscript::ChaiScript chai(/* unused */modulepaths, usepaths); |
| 66 | #else |
| 67 | modulepaths.push_back(""); |
| 68 | if (modulepath) |
| 69 | { |
| 70 | modulepaths.push_back(modulepath); |
| 71 | } |
| 72 | |
| 73 | // For this test we are going to load the dynamic stdlib |
| 74 | // to make sure it continues to work |
| 75 | chaiscript::ChaiScript_Basic chai( |
| 76 | std::make_unique<chaiscript::parser::ChaiScript_Parser<chaiscript::eval::Noop_Tracer, chaiscript::optimizer::Optimizer_Default>>(), |
| 77 | modulepaths,usepaths); |
| 78 | #endif |
| 79 | |
| 80 | std::vector<std::shared_ptr<std::thread> > threads; |
| 81 | |
| 82 | // Ensure at least two, but say only 7 on an 8 core processor |
| 83 | size_t num_threads = static_cast<size_t>(std::max(static_cast<int>(std::thread::hardware_concurrency()) - 1, 2)); |
| 84 | |
| 85 | std::cout << "Num threads: " << num_threads << '\n'; |
| 86 | |
| 87 | for (size_t i = 0; i < num_threads; ++i) |
| 88 | { |
| 89 | threads.push_back(std::make_shared<std::thread>(do_work, std::ref(chai), i)); |
| 90 | } |
| 91 | |
| 92 | for (size_t i = 0; i < num_threads; ++i) |
| 93 | { |
| 94 | threads[i]->join(); |
nothing calls this directly
no test coverage detected