On Wed, Feb 4, 2015 at 11:13 AM, ChrisLu <
chri...@gmail.com> wrote:
> Don't jump into conclusion so quickly. I am the author the OP referred to.
> The use case is this:
>
> One goroutine set one value x = "some_new_value" during a rare state
> transition, which usually takes 10s of seconds.
> Other goroutines acts on value x, and fails if something wrong. But the
> failure is expected during the transition period.
>
> Given the use case, I do not feel the need to add extra locks, channels etc.
> Simpler code is better.
> On Tuesday, February 3, 2015 at 7:40:14 AM UTC-8, Jan Mercl wrote:
>>
>> On Tue Feb 03 2015 at 16:24:51 吴延毅 <
wuya...@gmail.com> wrote:
>>
>> > Anyone else can help me?
>>
>> If one goroutine mutates a thing and concurrently another goroutine reads
>> the same bytes mutated by it without any synchronization, it's a data race
>> and anything can happen. No exceptions even though on some architectures one
>> can abuse the fact that some stores/loads might be invariably atomic without
>> asking for that. However, the same code on a different machine can fail.
>>
>> Synchronization can be achieved for example by using sync/atomic
>> primitives or via critical sections (sync.Mutex, sync.RWMutex, user written
>> semaphores, ...).
>>
>> It doesn't matter if the mutated thing is or is not a string variable,
>> string struct field etc. Only the backing array of s string is immutable and
>> thus immune to race conditions.
>>
>> -j
>>