mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-11-09 09:24:41 +00:00
Fix: Prevent race condition during pipe registration
This change introduces thread-safe pipe registration and unregistration functions using `sync.WaitGroup` and `atomic.Int64` to manage the count of registered pipes, addressing a race condition identified by the race detector.
This commit is contained in:
1 parent
56f5fe33d7
commit
f75e774bd5
2 files changed
+8
-6
No files matched your search
+2
-1
@@ -245,7 +245,8 @@ de la taxonomie et du FASTA non comprise ; ecoPrimers complet : 134 s et 350 s (
|
|||||||
**Bug existant repéré hors périmètre** : `go test -race` signale une course dans
|
**Bug existant repéré hors périmètre** : `go test -race` signale une course dans
|
||||||
`obiutils/pipe.go` (`globalLockerCounter` est un `int` incrémenté et décrémenté depuis plusieurs
|
`obiutils/pipe.go` (`globalLockerCounter` est un `int` incrémenté et décrémenté depuis plusieurs
|
||||||
goroutines, utilisé seulement pour des `log.Debugln`). Sans rapport avec obiprimers ; un `atomic.Int64`
|
goroutines, utilisé seulement pour des `log.Debugln`). Sans rapport avec obiprimers ; un `atomic.Int64`
|
||||||
suffirait. Non modifié (code partagé) : à décider.
|
suffisait. **Corrigé** (accord de l'utilisateur) : `globalLockerCounter` est un `atomic.Int64` dans
|
||||||
|
`pkg/obiutils/pipe.go` ; le test de bout en bout passe désormais sous `-race`.
|
||||||
|
|
||||||
Suite : étape 3 (recherche approchée des mots stricts, <= e substitutions, deux brins, dans exemples
|
Suite : étape 3 (recherche approchée des mots stricts, <= e substitutions, deux brins, dans exemples
|
||||||
et contre-exemples), puis paires et indices.
|
et contre-exemples), puis paires et indices.
|
||||||
@@ -2,12 +2,13 @@ package obiutils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var globalLocker sync.WaitGroup
|
var globalLocker sync.WaitGroup
|
||||||
var globalLockerCounter = 0
|
var globalLockerCounter atomic.Int64
|
||||||
|
|
||||||
// RegisterAPipe increments the global lock counter and adds a new pipe to the global wait group.
|
// RegisterAPipe increments the global lock counter and adds a new pipe to the global wait group.
|
||||||
//
|
//
|
||||||
@@ -15,8 +16,8 @@ var globalLockerCounter = 0
|
|||||||
// No return values.
|
// No return values.
|
||||||
func RegisterAPipe() {
|
func RegisterAPipe() {
|
||||||
globalLocker.Add(1)
|
globalLocker.Add(1)
|
||||||
globalLockerCounter++
|
n := globalLockerCounter.Add(1)
|
||||||
log.Debugln(globalLockerCounter, " Pipes are registered now")
|
log.Debugln(n, " Pipes are registered now")
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnregisterPipe decrements the global lock counter and signals that a pipe has finished.
|
// UnregisterPipe decrements the global lock counter and signals that a pipe has finished.
|
||||||
@@ -25,8 +26,8 @@ func RegisterAPipe() {
|
|||||||
// No return values.
|
// No return values.
|
||||||
func UnregisterPipe() {
|
func UnregisterPipe() {
|
||||||
globalLocker.Done()
|
globalLocker.Done()
|
||||||
globalLockerCounter--
|
n := globalLockerCounter.Add(-1)
|
||||||
log.Debugln(globalLockerCounter, "are still registered")
|
log.Debugln(n, "are still registered")
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitForLastPipe waits until all registered pipes have finished.
|
// WaitForLastPipe waits until all registered pipes have finished.
|
||||||
|
|||||||
Reference in new issue
Block a user