ZenQ
ZenQ copied to clipboard
Is Select() providing the same value twice or am i missing something here?
Had a section of code which pulls a value from a zenq queue:
if dat := zenq.Select(b.notifyQ, b.writeQ); dat != nil {
switch dat.(type) {
case *bounceNofity:
switch dat.(*bounceNofity).event {
case bShutdown:
model_debugf("BounceMap: writerLoop got shutdown")
shutdown = true
case bShutdownnow:
break writerLoop
}
case *Bounce:
bnc := dat.(*Bounce)
if bnc.writecb != nil {
bnc.writecb(bnc)
}
if bnc.writecb2 != nil {
bnc.writecb2(bnc)
}
}
When doing a tests of a 1000 concurrent "Bounce" pointers coming in to the zenq concurrently, i get a handful of duplicate reads from zenq.
When i switch the zenq over to a normal channel, I don't have this issue:
select {
case bnc := <-b.writeQ:
if bnc.writecb != nil {
bnc.writecb(bnc)
}
if bnc.writecb2 != nil {
bnc.writecb2(bnc)
}
case ev := <-b.notifyQ:
switch ev.event {
case bShutdown:
model_debugf("BounceMap: writerLoop got shutdown")
shutdown = true
case bShutdownnow:
break writerLoop
}
}
Provided 4 sources files to completely reproduce the test in question: TestBounceMap1000
I may well have a bug in my code. Or just don't understand something fundamental about Zenq - but by switching out to channels i dont have the issue.
go test -tags model_debug -v -run TestBounceMap
Also, on aarch64 machine - MacOS M1 Max
I will check this out and get back to you