On Mon, Nov 7, 2016 at 12:57 AM, wrote:
> All above discussion is talking about cpu excution order or memory order,
> lets make it easy and clear.
> If I use a mutex when create a temporary map to guarantee that this
> temporary map has been successully created, modified and
All above discussion is talking about cpu excution order or memory order,
lets make it easy and clear.
If I use a mutex when create a temporary map to guarantee that this
temporary map has been successully created, modified and set to gMap1.
Is it safe setting gMap1 pointer to gMap pointer when
Hi, the second one is better.
The lock should only protect the shared data. In this case, gMap.
In the first case, you are protecting some computations which are not accessing
any shared data.
On November 7, 2016, at 4:03 AM, 刘桂祥 wrote:
should I use ??
The second. The section in lock should be as short as possible.
--
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
should I use ??
mu.Lock()
temp := make(map[int]int)
temp[1] = 100
temp[2] = 200
gMap = temp
mu.Unlock()
or
temp := make(map[int]int)
temp[1] = 100
temp[2] = 200
mu.Lock()
gMap = temp
mu.Unlock()
在 2016年11月4日星期五 UTC+8下午9:59:45,Ian Lance
to be more forgiving.)
Michael
From: <golang-nuts@googlegroups.com> on behalf of 刘桂祥 <liuguixiang...@gmail.com>
Date: Friday, November 4, 2016 at 2:30 AM
To: golang-nuts <golang-nuts@googlegroups.com>
Cc: <liuguixiang...@gmail.com>
Subject: Re: [go-nuts] Multiple-reader
very thanks , I am unfamiliar with the cpu *out-of-order execution ,
but I doubt if my three line code is related ,it will reorder it ??*
在 2016年11月4日星期五 UTC+8下午1:38:12,Ian Lance Taylor写道:
>
> On Thu, Nov 3, 2016 at 10:28 PM, 刘桂祥
> wrote:
> >
> > In my write
On Thu, Nov 3, 2016 at 10:28 PM, 刘桂祥 wrote:
>
> In my write goroutine I don't modify the map key (data structure) but set
> the variable point to another map address ,this is a pointer assignment and
> is atomic
You're right, my previous reply was incorrect. My
In my write goroutine I don't modify the map key (data structure) but set
the variable point to another map address ,this is a pointer assignment
and is atomic
在 2016年11月4日星期五 UTC+8下午1:22:20,Ian Lance Taylor写道:
>
> On Thu, Nov 3, 2016 at 10:19 PM, 刘桂祥
> wrote:
> >
On Thu, Nov 3, 2016 at 10:19 PM, 刘桂祥 wrote:
> can you explain why whis ?
A map is basically a pointer to a complex data structure. Setting a
value in a map changes that data structure. If one goroutine is
reading from the data structure while a different goroutine
can you explain why whis ?
在 2016年11月4日星期五 UTC+8下午1:16:39,Ian Lance Taylor写道:
>
> On Thu, Nov 3, 2016 at 8:37 PM, 刘桂祥
> wrote:
> > // example.go
> >
> > package main
> >
> > var gMap = make(map[int]int)
> >
> > func w() {
> > temp := make(map[int]int)
> >
On Thu, Nov 3, 2016 at 8:37 PM, 刘桂祥 wrote:
> // example.go
>
> package main
>
> var gMap = make(map[int]int)
>
> func w() {
> temp := make(map[int]int)
> temp[1] = 100
> temp[2] = 200
> gMap = temp// Does the compiler or cpu will reorder temp[1]=100,
// example.go
package main
var gMap = make(map[int]int)
func w() {
temp := make(map[int]int)
temp[1] = 100
temp[2] = 200
gMap = temp// Does the compiler or cpu will reorder temp[1]=100,
temp[2]=200, gMap=temp ??
}
func r() {
local := gMap
println(local[1],
13 matches
Mail list logo