Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using atomic operations, cache consistency will cause some threads to endless loop? #43487

Closed
zlfu9527 opened this issue Jan 4, 2021 · 1 comment

Comments

@zlfu9527
Copy link

zlfu9527 commented Jan 4, 2021

What version of Go are you using (go version)?

$ go version
go version go1.13.5 darwin/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

When I test the following code, some threads will appear dead loop, and the threshold of I * J is about 60000. But when I add print (), " os.Creat (), or os.Open(), this will not happen.

//**************************** test demo ****************************
        var casValue = new(int64)
	*casValue = 0
	var old int64 = 0
	var new int64 = 1
	var container *list.List
	container = list.New()
	var wg sync.WaitGroup
	wg.Add(10)
	t1 := time.Now()
	for i := 0; i < 10; i++ {
		go func(i int) {
			for j := 0; j < 10000; {
				if atomic.CompareAndSwapInt64(casValue, old, new) {
					var test = "hello world,hello world,hello world"
					container.PushBack(test)
					*casValue = 0
					j++
				}
				println("hello")//、os.Create("test")、os.Open("test") is ok
			}
			println("casValue=", *casValue)
			wg.Done()
		}(i)
	}
	lentcy := time.Since(t1)
	wg.Wait()
	fmt.Println(container.Len())
//******************************************************************

What did you expect to see?

What did you see instead?

@zlfu9527 zlfu9527 changed the title Using atomic operations, cache consistency will cause some threads to loop? Using atomic operations, cache consistency will cause some threads to endless loop? Jan 4, 2021
@zlfu9527 zlfu9527 closed this as completed Jan 4, 2021
@davecheney
Copy link
Contributor

@fzl-yty please stop opening these issues.

Thank you for raising this issue. Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For asking questions, see:

@golang golang locked and limited conversation to collaborators Jan 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants