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 // corresponds to the last commit, and not the one when the file will be
// commited // commited
var _Commit = "38dcd98" var _Commit = "1c6ab1c"
var _Version = "Release 4.4.0" var _Version = "Release 4.4.0"
// Version returns the version of the obitools package. // 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] old, ok := stats[sval]
if !ok { if !ok {
old = 0 old = 0
} }
stats[sval] = old + desc.Weight(toAdd) stats[sval] = old + desc.Weight(toAdd)
sequence.annot_lock.Unlock()
sequence.SetAttribute(StatsOnSlotName(desc.Name), stats) // TODO: check if this is necessary sequence.SetAttribute(StatsOnSlotName(desc.Name), stats) // TODO: check if this is necessary
return retval return retval
} }
@ -228,7 +231,9 @@ func (sequence *BioSequence) Merge(tomerge *BioSequence, na string, inplace bool
smk := sequence.StatsOn(desc, na) smk := sequence.StatsOn(desc, na)
mmk := tomerge.StatsOn(desc, na) mmk := tomerge.StatsOn(desc, na)
sequence.annot_lock.Lock()
annotations[StatsOnSlotName(key)] = smk.Merge(mmk) annotations[StatsOnSlotName(key)] = smk.Merge(mmk)
sequence.annot_lock.Unlock()
} else { } else {
sequence.StatsPlusOne(desc, tomerge, na) sequence.StatsPlusOne(desc, tomerge, na)
} }