Skip to content

Commit 86e6e69

Browse files
fix tests
Signed-off-by: AdityaPandeyCN <[email protected]>
1 parent f065683 commit 86e6e69

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/ramcore/SamToNTuple.cxx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ void samtoramntuple_split_by_chromosome(const char *datafile, const char *output
180180
t.join();
181181
}
182182

183-
auto write_chromosome_parallel = [&](const std::string &chr) {
183+
std::mutex rnext_global_mutex;
184+
185+
auto write_chromosome_parallel = [&](const std::string &chr, std::mutex &rnext_mutex) {
184186
const auto &records = chromosome_records[chr];
185187

186188
std::string filename = std::string(output_prefix) + "_" + chr + ".root";
@@ -221,7 +223,12 @@ void samtoramntuple_split_by_chromosome(const char *datafile, const char *output
221223
recordPtr->SetPOS(sam_record.pos);
222224
recordPtr->SetMAPQ(sam_record.mapq);
223225
recordPtr->SetCIGAR(sam_record.cigar.c_str());
224-
recordPtr->SetREFNEXT(sam_record.rnext.c_str());
226+
227+
{
228+
std::lock_guard<std::mutex> lock(rnext_mutex);
229+
recordPtr->SetREFNEXT(sam_record.rnext.c_str());
230+
}
231+
225232
recordPtr->SetPNEXT(sam_record.pnext);
226233
recordPtr->SetTLEN(sam_record.tlen);
227234
recordPtr->SetSEQ(sam_record.seq.c_str());
@@ -262,7 +269,7 @@ void samtoramntuple_split_by_chromosome(const char *datafile, const char *output
262269
std::vector<std::thread> threads;
263270

264271
for (int i = 0; i < num_threads && chr_idx < chr_names.size(); ++i, ++chr_idx) {
265-
threads.emplace_back(write_chromosome_parallel, chr_names[chr_idx]);
272+
threads.emplace_back(write_chromosome_parallel, chr_names[chr_idx], std::ref(rnext_global_mutex));
266273
}
267274

268275
for (auto &t : threads) {

0 commit comments

Comments
 (0)