diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 6aace7732..6f3c459b2 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -1292,8 +1292,12 @@ PrintConfigDef::PrintConfigDef() def->readonly = true; def->min = 1; def->max = 16; - def->default_value = new ConfigOptionInt((boost::thread::hardware_concurrency() == 0) ? 2 : boost::thread::hardware_concurrency()); - + { + int threads = boost::thread::hardware_concurrency(); + if (threads == 0) threads = 2; + def->default_value = new ConfigOptionInt(threads); + } + def = this->add("toolchange_gcode", coString); def->label = "Tool change G-code"; def->tooltip = "This custom code is inserted right before every extruder change. Note that you can use placeholder variables for all Slic3r settings as well as [previous_extruder] and [next_extruder]."; diff --git a/xs/src/libslic3r/libslic3r.h b/xs/src/libslic3r/libslic3r.h index 77d30489d..89db6d81e 100644 --- a/xs/src/libslic3r/libslic3r.h +++ b/xs/src/libslic3r/libslic3r.h @@ -4,6 +4,7 @@ // this needs to be included early for MSVC (listing it in Build.PL is not enough) #include #include +#include #include #include #include @@ -119,9 +120,10 @@ template void parallelize(std::queue queue, boost::function func, int threads_count = boost::thread::hardware_concurrency()) { + if (threads_count == 0) threads_count = 2; boost::mutex queue_mutex; boost::thread_group workers; - for (int i = 0; i < threads_count; i++) + for (int i = 0; i < fminf(threads_count, queue.size()); i++) workers.add_thread(new boost::thread(&_parallelize_do, &queue, &queue_mutex, func)); workers.join_all(); }