Skip to content

Commit fc2cf14

Browse files
authored
Merge pull request #427 from DeterminateSystems/eelcodolstra/nix-378
boost::thread_resource_error improvements
2 parents b5c0faf + 5c862d7 commit fc2cf14

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/libexpr/parallel-eval.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ thread_local bool Executor::amWorkerThread{false};
1717

1818
unsigned int Executor::getEvalCores(const EvalSettings & evalSettings)
1919
{
20+
/* Note: the default number of cores is currently limited to 32
21+
due to scalability bottlenecks. */
2022
return evalSettings.evalProfilerMode != EvalProfilerMode::disabled ? 1
21-
: evalSettings.evalCores == 0UL ? Settings::getDefaultCores()
23+
: evalSettings.evalCores == 0UL ? std::min(32U, Settings::getDefaultCores())
2224
: evalSettings.evalCores;
2325
}
2426

@@ -32,8 +34,16 @@ Executor::Executor(const EvalSettings & evalSettings)
3234
{
3335
debug("executor using %d threads", evalCores);
3436
auto state(state_.lock());
37+
// FIXME: create worker threads on demand?
3538
for (size_t n = 0; n < evalCores; ++n)
36-
createWorker(*state);
39+
try {
40+
createWorker(*state);
41+
} catch (boost::thread_resource_error & e) {
42+
if (n == 0)
43+
throw Error("could not create any evaluator worker threads: %s", e.what());
44+
warn("could only create %d evaluator worker threads: %s", n, e.what());
45+
break;
46+
}
3747
}
3848

3949
Executor::~Executor()

0 commit comments

Comments
 (0)