diff options
author | haoping-ku <haoping.ku@dexon.org> | 2018-12-06 16:24:15 +0800 |
---|---|---|
committer | Jimmy Hu <jimmy.hu@dexon.org> | 2018-12-06 16:24:15 +0800 |
commit | a63e0d313300fc85eba8254963800a312fb14e9b (patch) | |
tree | 55bf36c3e5bbc45efe109ea9fad106c618498475 | |
parent | 8fa4b9fd7220b9650047ce6575a51b2cab8aa617 (diff) | |
download | dexon-consensus-a63e0d313300fc85eba8254963800a312fb14e9b.tar dexon-consensus-a63e0d313300fc85eba8254963800a312fb14e9b.tar.gz dexon-consensus-a63e0d313300fc85eba8254963800a312fb14e9b.tar.bz2 dexon-consensus-a63e0d313300fc85eba8254963800a312fb14e9b.tar.lz dexon-consensus-a63e0d313300fc85eba8254963800a312fb14e9b.tar.xz dexon-consensus-a63e0d313300fc85eba8254963800a312fb14e9b.tar.zst dexon-consensus-a63e0d313300fc85eba8254963800a312fb14e9b.zip |
simulation: fix concurrency issue, add lock (#361)
-rw-r--r-- | simulation/app.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/simulation/app.go b/simulation/app.go index 74bd6cd..464c521 100644 --- a/simulation/app.go +++ b/simulation/app.go @@ -159,9 +159,13 @@ func (a *simApp) TotalOrderingDelivered( blockHashes common.Hashes, mode uint32) { fmt.Println("OUTPUT", a.NodeID, mode, blockHashes) latencies := []time.Duration{} - for _, h := range blockHashes { - latencies = append(latencies, time.Since(a.blockTimestamps[h][blockEventConfirmed])) - } + func() { + a.lock.RLock() + defer a.lock.RUnlock() + for _, h := range blockHashes { + latencies = append(latencies, time.Since(a.blockTimestamps[h][blockEventConfirmed])) + } + }() blockList := &BlockList{ ID: a.DeliverID, BlockHash: blockHashes, |