Skip to content

Commit

Permalink
SL-18721 Viewer shutdown order changes
Browse files Browse the repository at this point in the history
Same thing as commit cf692c4
which was removed due to shutdown freezes.
Error thread is no longer there so doesn't cause any race sonditions,
was not able to repro any issues so will ask QA to test shutdown
  • Loading branch information
akleshchev committed Aug 11, 2023
1 parent 858cde0 commit edf0874
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions indra/llcommon/threadpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
#include "llevents.h"
#include "stringize.h"

LL::ThreadPool::ThreadPool(const std::string& name, size_t threads, size_t capacity):
LL::ThreadPool::ThreadPool(const std::string& name, size_t threads, size_t capacity, bool auto_shutdown):
super(name),
mQueue(name, capacity),
mName("ThreadPool:" + name),
mThreadCount(threads)
mThreadCount(threads),
mAutomaticShutdown(auto_shutdown)
{}

void LL::ThreadPool::start()
Expand All @@ -39,6 +40,13 @@ void LL::ThreadPool::start()
run(tname);
});
}

// Some threads might need to run longer than LLEventPumps
if (!mAutomaticShutdown)
{
return;
}

// Listen on "LLApp", and when the app is shutting down, close the queue
// and join the workers.
LLEventPumps::instance().obtain("LLApp").listen(
Expand Down
3 changes: 2 additions & 1 deletion indra/llcommon/threadpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace LL
* Pass ThreadPool a string name. This can be used to look up the
* relevant WorkQueue.
*/
ThreadPool(const std::string& name, size_t threads=1, size_t capacity=1024);
ThreadPool(const std::string& name, size_t threads=1, size_t capacity=1024, bool auto_shutdown = true);
virtual ~ThreadPool();

/**
Expand Down Expand Up @@ -66,6 +66,7 @@ namespace LL
std::string mName;
size_t mThreadCount;
std::vector<std::pair<std::string, std::thread>> mThreads;
bool mAutomaticShutdown;
};

} // namespace LL
Expand Down
3 changes: 2 additions & 1 deletion indra/llwindow/llwindowwin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ void LLWindowWin32::close()
// Is window is already closed?
if (!mWindowHandle)
{
mWindowThread->close();
return;
}

Expand Down Expand Up @@ -4590,7 +4591,7 @@ std::vector<std::string> LLWindowWin32::getDynamicFallbackFontList()
#endif // LL_WINDOWS

inline LLWindowWin32::LLWindowWin32Thread::LLWindowWin32Thread()
: ThreadPool("Window Thread", 1, MAX_QUEUE_SIZE)
: ThreadPool("Window Thread", 1, MAX_QUEUE_SIZE, false)
{
ThreadPool::start();
}
Expand Down

3 comments on commit edf0874

@Ansariel
Copy link
Contributor

@Ansariel Ansariel commented on edf0874 Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad news: This again randomly results in a deadlock during shutdown. The main thread is waiting on one thread to finish (threadpool.cpp line 81), while I have a bunch of threads which are waiting to get unblocked via their mutex (llthread.cpp line 343). All of these threads are related to the texture pipeline.

@akleshchev
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the info. Our tools did register an uptick of shutdown freezes but I was not able to repro, will see if I can figure it out.

@akleshchev
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't see anything wrong with this... Unfortunately will have to roll it back and think of an alternate solution, may be a tiny winow (like the one on startup) that says ''saving please wait"

Please sign in to comment.