Skip to content

Commit 9657d02

Browse files
authored
Exit the process when the last thread errors and there is no work to do (#235)
In PR #195, a regression was accidentally introduced. When the process exits due to an error, it would return 0. This fixes that regression by checking if there is any work left to do. If the last thread was halted by an error, the process will exit.
1 parent d33b001 commit 9657d02

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

runtime/include/lute/runtime.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct Runtime
3030
void runContinuously();
3131

3232
bool hasContinuations();
33+
bool hasThreads();
3334

3435
void schedule(std::function<void()> f);
3536

runtime/src/runtime.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ bool Runtime::runToCompletion()
9595
error += lua_debugtrace(L);
9696

9797
fprintf(stderr, "%s", error.c_str());
98-
continue;
98+
99+
// If we have no work to do, then exit the process.
100+
if (!hasThreads() && !hasContinuations())
101+
return false;
102+
else
103+
continue;
99104
}
100105

101106
if (next.cont)
@@ -138,6 +143,11 @@ bool Runtime::hasContinuations()
138143
return !continuations.empty();
139144
}
140145

146+
bool Runtime::hasThreads()
147+
{
148+
return !runningThreads.empty();
149+
}
150+
141151
void Runtime::schedule(std::function<void()> f)
142152
{
143153
std::unique_lock lock(continuationMutex);

0 commit comments

Comments
 (0)