Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/ExecutionEngine/Orc/TaskDispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class DynamicThreadPoolTaskDispatcher : public TaskDispatcher {
void shutdown() override;
private:
std::mutex DispatchMutex;
bool Running = true;
bool Shutdown = false;
size_t Outstanding = 0;
std::condition_variable OutstandingCV;

Expand Down
15 changes: 13 additions & 2 deletions llvm/lib/ExecutionEngine/Orc/TaskDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ void DynamicThreadPoolTaskDispatcher::dispatch(std::unique_ptr<Task> T) {
{
std::lock_guard<std::mutex> Lock(DispatchMutex);

// Reject new tasks if they're dispatched after a call to shutdown.
if (Shutdown)
return;

if (IsMaterializationTask) {

// If this is a materialization task and there are too many running
Expand All @@ -54,6 +58,14 @@ void DynamicThreadPoolTaskDispatcher::dispatch(std::unique_ptr<Task> T) {
// Run the task.
T->run();

// Reset the task to free any resources. We need this to happen *before*
// we notify anyone (via Outstanding) that this thread is done to ensure
// that we don't proceed with JIT shutdown while still holding resources.
// (E.g. this was causing "Dangling SymbolStringPtr" assertions).
T.reset();

// Check the work queue state and either proceed with the next task or
// end this thread.
std::lock_guard<std::mutex> Lock(DispatchMutex);
if (!MaterializationTaskQueue.empty()) {
// If there are any materialization tasks running then steal that work.
Expand All @@ -64,7 +76,6 @@ void DynamicThreadPoolTaskDispatcher::dispatch(std::unique_ptr<Task> T) {
IsMaterializationTask = true;
}
} else {
// Otherwise decrement work counters.
if (IsMaterializationTask)
--NumMaterializationThreads;
--Outstanding;
Expand All @@ -78,7 +89,7 @@ void DynamicThreadPoolTaskDispatcher::dispatch(std::unique_ptr<Task> T) {

void DynamicThreadPoolTaskDispatcher::shutdown() {
std::unique_lock<std::mutex> Lock(DispatchMutex);
Running = false;
Shutdown = true;
OutstandingCV.wait(Lock, [this]() { return Outstanding == 0; });
}
#endif
Expand Down
1 change: 1 addition & 0 deletions llvm/tools/llvm-jitlink/llvm-jitlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2562,6 +2562,7 @@ int main(int argc, char *argv[]) {
if (Timers)
Timers->JITLinkTG.printAll(errs());
reportLLVMJITLinkError(EntryPoint.takeError());
ExitOnErr(S->ES.endSession());
exit(1);
}

Expand Down
Loading