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

Update parallel-computing.md #34431

Closed
wants to merge 1 commit into from
Closed

Update parallel-computing.md #34431

wants to merge 1 commit into from

Conversation

OkonSamuel
Copy link
Contributor

I got a different result on my system when i ran the following codeblock

julia> i = Threads.Atomic{Int}(0);

julia> ids = zeros(4);

julia> old_is = zeros(4);

julia> Threads.@threads for id in 1:4
           old_is[id] = Threads.atomic_add!(i, id)
           ids[id] = id
       end

The result gotten in the julia manual is

julia> old_is
4-element Array{Float64,1}:
 0.0
 1.0
 7.0
 3.0

While on my system i got

julia> ids
4-element Array{Float64,1}:
 0.0
 1.0
 3.0
 6.0

Copy link
Member

@Keno Keno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either result is fine, the output depends on the thread execution order. Of course that makes it a bit of a confusing example in this place. @kshyatt @vchuravy Looks like you wrote this section. What was the intention behind this example.

@vchuravy
Copy link
Member

Maybe we should remove that example and use the one afterwards since it is independent of order of execution. I believe that particular one is from @kshyatt so let's wait for her to chime in.

@vchuravy vchuravy self-assigned this Jan 19, 2020
@OkonSamuel
Copy link
Contributor Author

Ok

@ViralBShah ViralBShah added the docs This change adds or pertains to documentation label May 15, 2020
@ViralBShah
Copy link
Member

How about just mention for this example that the results will be printed in order of execution, and that it may different every time the program is run?

@ViralBShah ViralBShah added the multithreading Base.Threads and related functionality label Dec 6, 2020
@vtjnash vtjnash closed this Apr 20, 2021
@vtjnash
Copy link
Member

vtjnash commented Apr 20, 2021

I don't think we need any updates, since the point is to make people avoid this unless they understand race conditions. Although I can include changes in #37847 (where I'm already editing this) if something is desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation multithreading Base.Threads and related functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants