Skip to content

Commit

Permalink
Set max sleep period for threads to prevent hanging
Browse files Browse the repository at this point in the history
  • Loading branch information
complexlogic committed May 18, 2022
1 parent 3cc53b1 commit 485ac7f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10)
message(FATAL_ERROR "GCC 10 and later supported only")
endif ()

# Set Visual Studio startup project
if (WIN32)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${EXECUTABLE_TITLE})
endif ()

configure_file(
"${PROJECT_SOURCE_DIR}/config/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
Expand Down
Empty file modified config/PKGBUILD
100644 → 100755
Empty file.
Empty file modified docs/BUILDING.md
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions src/easymode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ void WorkerThread::work()
this->main_cv->notify_all();
main_lock.unlock();
}

// Wait until we get a new job from the main thread
this->thread_cv.wait(thread_lock);
this->thread_cv.wait_for(thread_lock, std::chrono::seconds(MAX_THREAD_SLEEP));
}

return;
Expand Down Expand Up @@ -555,7 +555,7 @@ void scan_easy(const char *directory, const char *overrides_file)
// Wait for threads to finish scanning
int num_active = active_threads.size();
while (num_active) {
main_cv.wait(main_lock);
main_cv.wait_for(main_lock, std::chrono::seconds(MAX_THREAD_SLEEP));
for (WorkerThread *at : active_threads) {
if (at->is_finished(error)) {
num_active--;
Expand Down
2 changes: 2 additions & 0 deletions src/easymode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#define CALC_TIME 1
#endif

#define MAX_THREAD_SLEEP 30

typedef enum {
INVALID = -1,
MP2,
Expand Down

0 comments on commit 485ac7f

Please sign in to comment.