Just wrapping a write with a mutex is not enough; you have to wrap all the
reads as well. In this case that's not possible because there are reads of
time.Local all over the place. Anyway, as has been said, time.Local should
never be written to in user code.

On Fri, Nov 30, 2018 at 7:46 AM Agniva De Sarker <
agniva.quicksil...@gmail.com> wrote:

> Can you show us the code ? It would help
>
> Are you trying to set a variable of type time.Location ? Or are you trying
> to set time.Local to something else ?
>
> Like Ian said, if you want to change the location of a specific time
> value, use the In method.
>
> > But there are lots of place that time.Location used by time package of
> golang. For example: time.Now(), time.locabs()
>
> > I can’t change them.
> I don't understand. Use time.Now() uses the time.Local variable. But all
> you need to do is wrap the setting of time.Local value with a mutex. Why is
> it not possible to do that ?
>
>
>
>
> On Friday, 30 November 2018 11:31:42 UTC+5:30, Ian Lance Taylor wrote:
>>
>> On Thu, Nov 29, 2018 at 9:47 PM <zhangzh...@gmail.com> wrote:
>> >
>> > My go version is 1.11.
>> >
>> > When I set time.Location, then …
>> >
>> > ==================
>> > WARNING: DATA RACE
>> > Write at 0x000002e275d0 by main goroutine:
>> >   vcs.taiyouxi.net/platform/planx/timeutil.SetTimeLocal()
>> >       /Users/zhangzhen/serverthreekingdom/src/
>> vcs.taiyouxi.net/platform/planx/timeutil/time_util.go:51 +0xb4
>> >   vcs.taiyouxi.net/platform/planx/timeutil.init.0()
>> >       /Users/zhangzhen/serverthreekingdom/src/
>> vcs.taiyouxi.net/platform/planx/timeutil/time_util.go:42 +0x43
>> >   vcs.taiyouxi.net/platform/planx/timeutil.init()
>> >       <autogenerated>:1 +0xd0
>> >   vcs.taiyouxi.net/jws2/common/time.init()
>> >       <autogenerated>:1 +0xa6
>> >   vcs.taiyouxi.net/jws2/gamex/account/account.init()
>> >       <autogenerated>:1 +0xa6
>> >   vcs.taiyouxi.net/jws2/gamex/logics.init()
>> >       <autogenerated>:1 +0xa6
>> >   vcs.taiyouxi.net/jws2/gamex/cmds/gamemode.init()
>> >       <autogenerated>:1 +0xa6
>> >   main.init()
>> >       <autogenerated>:1 +0xa6
>> >
>> > Previous read at 0x000002e275d0 by goroutine 8:
>> >   time.Now()
>> >       /Users/zhangzhen/.gvm/gos/go1.11/src/time/time.go:1060 +0xcf
>> >   time.sendTime()
>> >       /Users/zhangzhen/.gvm/gos/go1.11/src/time/sleep.go:141 +0x44
>> >
>> > Goroutine 8 (running) created at:
>> >   runtime.(*timersBucket).addtimerLocked()
>> >       /Users/zhangzhen/.gvm/gos/go1.11/src/runtime/time.go:170 +0x113
>> >
>> vcs.taiyouxi.net/vendor/github.com/siddontang/go/timingwheel.NewTimingWheel()
>> >       /Users/zhangzhen/serverthreekingdom/src/
>> vcs.taiyouxi.net/vendor/github.com/siddontang/go/timingwheel/timingwheel.go:39
>> +0x2a0
>> >   vcs.taiyouxi.net/platform/planx/util.init()
>> >       /Users/zhangzhen/serverthreekingdom/src/
>> vcs.taiyouxi.net/platform/planx/util/timer_helper.go:10 +0xf3
>> >   vcs.taiyouxi.net/platform/planx/metrics.init()
>> >       <autogenerated>:1 +0xbf
>> >   vcs.taiyouxi.net/jws2/gamex/cmds/gamemode.init()
>> >       <autogenerated>:1 +0x9c
>> >   main.init()
>> >       <autogenerated>:1 +0xa6
>> > ==================
>> >
>> > The feature of golang is goroutine, and it is a normal situation that
>> get time in different goroutine.
>> > But only can set time.Location in one goroutine. So the Data Race is
>> inevitable.
>> >
>> >
>> > And there is the replay from agnivade 3
>> >
>> > “It is not a bug. Please synchronize access to time.Location using
>> synchronization primitives in the sync andsync/atomic packages.”
>> >
>> >
>> > But there are lots of place that time.Location used by time package of
>> golang. For example: time.Now(), time.locabs()
>> > I can’t change them.
>> >
>> >
>> > So, What should I do ? Please help me.
>>
>> You said time.Location.  Do you mean time.Local?  It's true that you
>> should never change time.Local.  Why  do you want to?  If you want to
>> change the location of a specific time.Time value, call the In method.
>>
>> Ian
>>
> --
> 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.
>

-- 
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.

Reply via email to