Re: [go-nuts] atomic.Add*() doesn't produce unique values

2019-12-01 Thread Michael Jones
true. not roust that way. also, it uses "Go array bounds checking" as the implicit test for crazy out of range values. just a 5 min stream of consciousness hack to defend the honor of the Go atomic primitives. ;-) It was typed one handed while the the other propped up my macbook here in bed. easily

Re: [go-nuts] atomic.Add*() doesn't produce unique values

2019-12-01 Thread Robert Engels
Sorry, I hadn’t looked at the code, but after reviewing doesn’t your code not detect the case where a value was skipped ? (... not that it could happen - but for completeness of the robust test) > On Dec 1, 2019, at 10:44 PM, Michael Jones wrote: > > not necessary as the testing and updating i

Re: [go-nuts] atomic.Add*() doesn't produce unique values

2019-12-01 Thread Michael Jones
"Oh you've allocated a bit array for every value in the test range, then checked for gaps in it?" Yes. What I should have said. (Though the test looks not for gaps but for two pigeons in one hole, but the same idea.) On Sun, Dec 1, 2019 at 8:44 PM Michael Jones wrote: > not necessary as the tes

Re: [go-nuts] atomic.Add*() doesn't produce unique values

2019-12-01 Thread Michael Jones
not necessary as the testing and updating is only done in one place by one the main goroutine. On Sun, Dec 1, 2019 at 7:46 PM Robert Engels wrote: > The updating of the bit array if shared needs to atomic as well, probably > with a read and cas. > > On Dec 1, 2019, at 9:19 PM, Liam wrote: > > 

Re: [go-nuts] atomic.Add*() doesn't produce unique values

2019-12-01 Thread Robert Engels
The updating of the bit array if shared needs to atomic as well, probably with a read and cas. > On Dec 1, 2019, at 9:19 PM, Liam wrote: > >  > Oh you've allocated a bit array for every value in the test range, then > checked for gaps in it? > >> On Sunday, December 1, 2019 at 2:21:55 PM U

Re: [go-nuts] atomic.Add*() doesn't produce unique values

2019-12-01 Thread Liam
Oh you've allocated a bit array for every value in the test range, then checked for gaps in it? On Sunday, December 1, 2019 at 2:21:55 PM UTC-8, Michael Jones wrote: > > Oh! That's just a bit per integer in the test range 0..total-1. Since Go > (and everything else) lacks a bit type, I just type

Re: [go-nuts] atomic.Add*() doesn't produce unique values

2019-12-01 Thread Michael Jones
agree, makes sense. also if you trust the compiler, change to use the mod function, etc. On Sun, Dec 1, 2019 at 2:31 PM robert engels wrote: > I’d prefer v / 8 over v >> 3 - provides more context in my opinion. The > compiler will change to right shift if more efficient anyway. > > On Dec 1, 201

Re: [go-nuts] atomic.Add*() doesn't produce unique values

2019-12-01 Thread robert engels
I’d prefer v / 8 over v >> 3 - provides more context in my opinion. The compiler will change to right shift if more efficient anyway. > On Dec 1, 2019, at 4:21 PM, Michael Jones wrote: > > Oh! That's just a bit per integer in the test range 0..total-1. Since Go (and > everything else) lacks a

Re: [go-nuts] atomic.Add*() doesn't produce unique values

2019-12-01 Thread Michael Jones
Oh! That's just a bit per integer in the test range 0..total-1. Since Go (and everything else) lacks a bit type, I just type such code automatically. Bytes hold 8 bits. Array size must be rounded up, so a := make([]byte, (total+8-1)/8) array index for test integer n is n/8, so "n>>3" bit index f

Re: [go-nuts] atomic.Add*() doesn't produce unique values

2019-11-30 Thread Liam
I wrote a less-sophisticated version of your test, then realized I'd misspent my time; all I needed was to change the atomic.Add*() to a mutex-protected counter, and see whether my app still failed; it did. But since you took the trouble, I read your code, and would like to understand your coll

Re: [go-nuts] atomic.Add*() doesn't produce unique values

2019-11-30 Thread Michael Jones
As a follow-up, some more timing: *47088064 atomic increments/sec (my original email above for heavy synchronization conflict incrementing)* 142049067 atomic increments/sec when each goroutine has its own atomic update target. (Not testing global synchronization/mutex, just the overhead of conges

Re: [go-nuts] atomic.Add*() doesn't produce unique values

2019-11-30 Thread Michael Jones
Liam, I just wrote a little stress test program for you. Maybe it will make you less stressed. ;-) https://play.golang.org/p/5_7Geyczd1V 4 CPU 2016 MacBook Pro: *celeste:atom mtj$ go run main.go* *32 concurrent workers* *128 batches of 1048576 atomic increments, 134217728 total increments* *2.85

Re: [go-nuts] atomic.Add*() doesn't produce unique values

2019-11-30 Thread Robert Engels
If this was broken I think a lot of things would break. > On Nov 30, 2019, at 1:56 PM, Liam wrote: > >  > The stress test for my app fails frequently with what looks like a collision > in atomic.AddUint64() results, so I wondered whether I had misunderstood > atomic-add. > > So far I can't

Re: [go-nuts] atomic.Add*() doesn't produce unique values

2019-11-30 Thread Liam
The stress test for my app fails frequently with what looks like a collision in atomic.AddUint64() results, so I wondered whether I had misunderstood atomic-add. So far I can't reproduce it with a small program, so I've probably misunderstood my app :-) On Friday, November 29, 2019 at 6:41:39

Re: [go-nuts] atomic.Add*() doesn't produce unique values

2019-11-29 Thread Kurtis Rader
On Fri, Nov 29, 2019 at 6:21 PM Liam wrote: > Does atomic.AddInt32(&x, 1) always yield unique values for concurrent > callers? > > I'm guessing not, because (I think) I'm seeing that two callers get x+2, > neither gets x+1. > That shouldn't happen, AFAICT. Can you share the code where the incorr

Re: [go-nuts] atomic.Add*() doesn't produce unique values

2019-11-29 Thread burak serdar
On Fri, Nov 29, 2019 at 7:21 PM Liam wrote: > > Does atomic.AddInt32(&x, 1) always yield unique values for concurrent callers? > > I'm guessing not, because (I think) I'm seeing that two callers get x+2, > neither gets x+1. That should not happen, afaik. Do you have code you can share? > > Is t

[go-nuts] atomic.Add*() doesn't produce unique values

2019-11-29 Thread Liam
Does atomic.AddInt32(&x, 1) always yield unique values for concurrent callers? I'm guessing not, because (I think) I'm seeing that two callers get x+2, neither gets x+1. Is there a way to generate unique values with pkg atomic, or is a mutex required? -- You received this message because you