vgteam / vg

tools for working with genome variation graphs
https://biostars.org/tag/vg/
Other
1.1k stars 194 forks source link

Mapper::aligner thread safety #448

Closed ekg closed 8 years ago

ekg commented 8 years ago

When the mapper is called in banded mode via vg msga, several threads can try to access the aligner object in the mapper at the same time. This can cause segfaults and other weirdness.

I would just fix this but I feel I should mention it because I'm having trouble figuring out why this change only seems to be causing segfaults when run on the result of merging current master with the mem-threader branch.

It seems that (given the passing tests) this problem should be something I've introduced, but I'm at a complete loss for how. Also, it seems that things are structured such that we'll get the race on the current master.

Specifically, in vg msga the same aligner is being hit by multiple threads that are all using the same mapper:

The threads are launched here:

https://github.com/vgteam/vg/blob/6d385dd69e2140b79a105c5efa4e69ae53cd586d/src/mapper.cpp#L898

And sometimes they all decide to reach this point at the same time:

https://github.com/vgteam/vg/blob/6d385dd69e2140b79a105c5efa4e69ae53cd586d/src/mapper.cpp#L136-L143

:boom:

Why doesn't this explode on travis or before I make the merge?

ekg commented 8 years ago

My solution to this is to tell the Mapper the number of threads we should be able to support.

It can then initialize an array of QualAdjustedAligner objects.