Skip to content

Commit

Permalink
Merge pull request #13 from salesforce/guard-thread-exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
twarit-waikar authored Mar 1, 2022
2 parents 583171b + b647f01 commit cc06936
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions p4-fusion/thread_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ void ThreadPool::Wait()

void ThreadPool::RaiseCaughtExceptions()
{
std::unique_lock<std::mutex> lock(m_ThreadExceptionsMutex);

for (auto& exceptionPtr : m_ThreadExceptions)
{
if (exceptionPtr)
Expand Down Expand Up @@ -123,6 +125,8 @@ void ThreadPool::Initialize(int size)
}
catch (const std::exception& e)
{
std::unique_lock<std::mutex> lock(m_ThreadExceptionsMutex);

m_ThreadExceptions[i] = std::current_exception();
}
m_JobsProcessing--;
Expand Down
1 change: 1 addition & 0 deletions p4-fusion/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ThreadPool
typedef std::function<void(P4API*)> Job;

std::vector<std::thread> m_Threads;
std::mutex m_ThreadExceptionsMutex;
std::vector<std::exception_ptr> m_ThreadExceptions;
std::vector<std::string> m_ThreadNames;
std::vector<P4API> m_P4Contexts;
Expand Down

0 comments on commit cc06936

Please sign in to comment.