-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
async can't modify out-of-scope simple variables #7813
Comments
All these constructs copy bindings, since they were designed for distributed memory where another processor's variables cannot (efficiently), and should not be updated this way. Use |
Great, that fixed my problem, Jeff! For those looking at this in the future, I was able to get something that "just works" by changing my x = 0
@sync begin
x += 10
t = @task begin
x += 20
end
Base.sync_add(t)
Base.enq_work(t)
end
println("Unboxed: $x") |
I think we should probably change |
Let us imagine we have a simple variable, such as a number. We call an
@async
block that uses it and modifies it, but are then surprised that the value is not reflected in the outer scope. Example:Result:
Is there any way this can be fixed? I feel like this has something to do with the fact that
x
is immutable object.The text was updated successfully, but these errors were encountered: