Skip to content

Commit

Permalink
Release the lock before notifying the waiting thread in destructor.
Browse files Browse the repository at this point in the history
This is consistent with the other uses of notify_one(), otherwise the waiting
thread would block immediately and need to wait for the lock to be released.
  • Loading branch information
LTLA committed Jul 15, 2024
1 parent f301081 commit ad206e3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.24)

project(byteme
VERSION 1.2.1
VERSION 1.2.2
DESCRIPTION "No-frills byte streaming from file"
LANGUAGES CXX)

Expand Down
3 changes: 2 additions & 1 deletion include/byteme/PerByte.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,10 @@ class PerByteParallel {
*/
~PerByteParallel() {
if (!my_finished) {
std::lock_guard lck(my_mut);
std::unique_lock lck(my_mut);
my_finished = true;
my_ready_input = true;
lck.unlock(); // releasing the lock so that the notified thread doesn't immediately block.
my_cv.notify_one();
}
my_thread.join();
Expand Down

0 comments on commit ad206e3

Please sign in to comment.