-
Notifications
You must be signed in to change notification settings - Fork 630
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
Race on global variable: factorials #368
Comments
Hi @nasermirzaei89! Thanks for bringing this issue up. |
We opted to implement our own Taylor Series calculator for exponents in the 1/n format ( I'm working on moving it to a public repo. Benchmarks are promising:
EDIT: This is the repo, but the generics usage is probably affecting the benchmarks. |
Decimal's Pow function is not thread-safe, so we need to lock it manually. This is a workaround, we need to remove the lock after Decimal will be fixed or find a better solution. shopspring/decimal#368
We get a RACE error on running tests in the production with the flag
-race
enabled.And the stack shows it comes from here:
I believe that the reason is multiple goroutines are calling method
ExpTaylor
and this method manipulates the shared variablefactorials
(https://github.com/shopspring/decimal/blob/master/decimal.go#L84).As you used a global variable for caching factorials (#229), it's not goroutine safe and should have a lock.
The text was updated successfully, but these errors were encountered: