Skip to content

Commit

Permalink
threads are always tricky
Browse files Browse the repository at this point in the history
  • Loading branch information
gf777 committed Dec 26, 2024
1 parent a619476 commit ddd6f33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/reads.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class InReads {
LenVector<float> readLens;
uint64_t totA=0, totT=0, totC=0, totG=0, totN=0;

std::atomic<bool> streamOutput{false};
bool streamOutput = false;
std::thread writer;
std::condition_variable writerMutexCondition;

Expand Down
9 changes: 7 additions & 2 deletions src/reads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,14 @@ void InReads::closeStream() {
if (bam)
closeBam();

streamOutput = false;
if (writer.joinable())
if (writer.joinable()) {
{
std::unique_lock<std::mutex> lck(mtx);
streamOutput = false;
}
writerMutexCondition.notify_one();
writer.join();
}
}

void InReads::writeToStream() {
Expand Down

0 comments on commit ddd6f33

Please sign in to comment.