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

internal.NewSpinLock about runtime.Gosched() #65

Closed
jjshi opened this issue Nov 28, 2019 · 3 comments
Closed

internal.NewSpinLock about runtime.Gosched() #65

jjshi opened this issue Nov 28, 2019 · 3 comments
Assignees
Labels
question Further information is requested waiting for response waiting for the response from commenter

Comments

@jjshi
Copy link

jjshi commented Nov 28, 2019

I see that internal.NewSpinLock() is internal Lock. Why don't use sync.Mutex?
runtime.Gosched() is put current goroutine to global run queue tail.
Hope your response.

@jjshi jjshi added the proposal Proposal for this repo label Nov 28, 2019
@panjf2000 panjf2000 added question Further information is requested and removed proposal Proposal for this repo labels Nov 28, 2019
@panjf2000
Copy link
Owner

panjf2000 commented Nov 28, 2019

The reason why I chose spinlock over mutex is that the goroutine would be put into wait queue and awaked when the mutex lock is released by another goroutine, but most of the cases using ants won't hold the lock for a long time, which makes all those actions of mutex worthless, so there will be a higher performance using spinlock.

@panjf2000 panjf2000 added the waiting for response waiting for the response from commenter label Nov 28, 2019
@panjf2000
Copy link
Owner

panjf2000 commented Dec 1, 2019

@jjshi
Do you still have questions about this? or other questions? If not, please close this issue, thanks!

@jjshi
Copy link
Author

jjshi commented Dec 4, 2019

thanks @panjf2000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested waiting for response waiting for the response from commenter
Projects
None yet
Development

No branches or pull requests

2 participants