Skip to content

Commit

Permalink
Fix deadlock after an external std::exit() call
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Dec 16, 2023
1 parent 371c8ea commit afbd23b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions far/filesystemwatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class background_watcher: public singleton<background_watcher>
{
IMPLEMENTS_SINGLETON;

public:
void add(const FileSystemWatcher* Client)
{
Expand Down Expand Up @@ -116,7 +118,12 @@ class background_watcher: public singleton<background_watcher>
const auto Result = os::handle::wait_any(m_Handles);

if (Result == 0)
{
if (m_Exit)
return;

continue;
}

{
SCOPED_ACTION(std::scoped_lock)(m_CS);
Expand All @@ -136,12 +143,19 @@ class background_watcher: public singleton<background_watcher>
}
}

~background_watcher()
{
m_Exit = true;
m_Update.set();
}

os::critical_section m_CS;
os::event
m_Update{ os::event::type::automatic, os::event::state::nonsignaled },
m_UpdateDone{ os::event::type::automatic, os::event::state::nonsignaled };
std::vector<const FileSystemWatcher*> m_Clients;
std::vector<HANDLE> m_Handles{ m_Update.native_handle() };
std::atomic_bool m_Exit{};
os::thread m_Thread;
};

Expand Down

0 comments on commit afbd23b

Please sign in to comment.