Sorry and the outer loop is the only reader. It probably reports it as a race though since there are multiple writers - but they all write the same value. Technically still a data race depending on if the word splits when writing. 

On Jul 6, 2024, at 10:20 AM, Robert Engels <reng...@ix.netcom.com> wrote:


That is not a data race. The wait group is a synchronization barrier. 

On Jul 6, 2024, at 9:34 AM, 'qiu laidongfeng2' via golang-nuts <golang-nuts@googlegroups.com> wrote:

I know not to write code with data races?
The problem is that I find that this code always outputs 1 on the amd64 machine,
I am not sure what effect this data competition has on the execution result,
whether it is an inevitable result of the amd64 machine to always output 1 or I am lucky to encounter that it is always output 1, so I ask.

在2024年7月6日星期六 UTC+8 22:20:57<Ian Lance Taylor> 写道:
On Sat, Jul 6, 2024 at 7:04 AM 'qiu laidongfeng2' via golang-nuts
<golan...@googlegroups.com> wrote:
>
> Does data race in this program affect execution results?
> In amd64, it always output1.

If you want to write code like this, use the sync/atomic package.
Don't write code with data races.

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/6a2c3ebf-b5e9-4a18-bcf3-d7a4b5fc24a4n%40googlegroups.com.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/40CF9EFD-6B8B-431A-ABD8-DE994F044156%40ix.netcom.com.

Reply via email to