Patch a concurrent access problem

This commit is contained in:
Eric Coissac
2025-06-17 12:05:42 +02:00
parent 1c6ab1c559
commit efc3f3af29
2 changed files with 6 additions and 1 deletions

View File

@ -8,7 +8,7 @@ import (
// corresponds to the last commit, and not the one when the file will be
// commited
var _Commit = "38dcd98"
var _Commit = "1c6ab1c"
var _Version = "Release 4.4.0"
// Version returns the version of the obitools package.

View File

@ -174,12 +174,15 @@ func (sequence *BioSequence) StatsPlusOne(desc StatsOnDescription, toAdd *BioSeq
}
sequence.annot_lock.Lock()
old, ok := stats[sval]
if !ok {
old = 0
}
stats[sval] = old + desc.Weight(toAdd)
sequence.annot_lock.Unlock()
sequence.SetAttribute(StatsOnSlotName(desc.Name), stats) // TODO: check if this is necessary
return retval
}
@ -228,7 +231,9 @@ func (sequence *BioSequence) Merge(tomerge *BioSequence, na string, inplace bool
smk := sequence.StatsOn(desc, na)
mmk := tomerge.StatsOn(desc, na)
sequence.annot_lock.Lock()
annotations[StatsOnSlotName(key)] = smk.Merge(mmk)
sequence.annot_lock.Unlock()
} else {
sequence.StatsPlusOne(desc, tomerge, na)
}