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

WeakRef: Set initial value atomically #52212

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jpsamaroo
Copy link
Member

@jpsamaroo jpsamaroo commented Nov 17, 2023

Since all accesses to WeakRef from Julia code are atomic, we might as well be atomic when accessing their contents from C (even if it may not matter in practice). Otherwise it's technically possible for another thread to experience a torn read.

@jpsamaroo jpsamaroo added the multithreading Base.Threads and related functionality label Nov 17, 2023
@vtjnash
Copy link
Member

vtjnash commented Nov 17, 2023

You need to fix up all the other uses, such as (make tidysrc --output-sync -jN to list all of them):

                    wr->value = (jl_value_t*)jl_nothing;

Note that it should not be technically possible in this particular case, since we haven't published the value yet (so the compiler is free to turn this back into a normal store anyways)

@vtjnash
Copy link
Member

vtjnash commented Nov 20, 2023

Since all accesses to WeakRef from Julia code are atomic.

Note that this is only weakly true from Julia. And this object is otherwise only accessed from GC, which is already atomic in accessing all fields of all objects

julia> Base.isfieldatomic(WeakRef, 1)
false

@jpsamaroo
Copy link
Member Author

jpsamaroo commented Dec 1, 2023

Aside from the test failures, which appear unrelated, is this good to go @vtjnash ?

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

Successfully merging this pull request may close these issues.

3 participants