Re: [go-nuts] [NEWBIE] syncmap - how to use it correctly

2018-04-13 Thread vadim kulibaba
Wow, thank you, Jan

пятница, 13 апреля 2018 г., 15:43:51 UTC+3 пользователь Jan Mercl написал:
>
> On Fri, Apr 13, 2018 at 2:29 PM > 
> wrote:
>
> > What i do wrong? 
>
> The code relies on the bool value in 'ok', returned from .Load(), but that 
> _does not_ mean some other goroutine, once you remove the mutex.Lock(), 
> cannot insert a value for the same key the moment the call of .Load() 
> returned.
>
> -- 
>
> -j
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] [NEWBIE] syncmap - how to use it correctly

2018-04-13 Thread Jan Mercl
On Fri, Apr 13, 2018 at 2:29 PM  wrote:

> What i do wrong?

The code relies on the bool value in 'ok', returned from .Load(), but that
_does not_ mean some other goroutine, once you remove the mutex.Lock(),
cannot insert a value for the same key the moment the call of .Load()
returned.

-- 

-j

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] [NEWBIE] syncmap - how to use it correctly

2018-04-13 Thread vadim . kulibaba
Please explain me(

I dont understand why syncmap - not sync

If i try Load/Store  from multiple goroutins - i have vary values with same 
key in syncmap  

If i try lock with mutex- all ok. But is syncmap not thread safe by default?

Locked version of function: 
https://github.com/recoilme/slowpoke/blob/master/channel/main.go#L497
And async test: 
https://github.com/recoilme/slowpoke/blob/master/channel/main_test.go#L100

If i remove lock mutex from load/store of syncmap - test will pass or fail 
- and i will have muliple values with same key.

What i do wrong? 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.