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

Add do-block syntax for Semaphore acquire. Add Semaphore tests #43730

Merged
merged 6 commits into from
Jan 11, 2022

Conversation

IanButterworth
Copy link
Member

Add do-block syntax for Semaphore acquire

s = Base.Semaphore(2)
@sync for _ in 1:100
    Threads.@spawn begin
        Base.acquire(s) do
            foo()
        end
    end
end

Also, from what I can tell Semaphore wasn't tested in Base before this

@vchuravy vchuravy requested a review from vtjnash January 10, 2022 02:08
base/lock.jl Outdated Show resolved Hide resolved
@tkf tkf added needs compat annotation Add !!! compat "Julia x.y" to the docstring multithreading Base.Threads and related functionality labels Jan 10, 2022
@IanButterworth IanButterworth removed the needs compat annotation Add !!! compat "Julia x.y" to the docstring label Jan 10, 2022
test/misc.jl Outdated Show resolved Hide resolved
@IanButterworth
Copy link
Member Author

@tkf it just occurred to me that the do-block should probably return the return value of f(), in the same way that lock(f.. does..

I just pushed that and copied the code style from lock(f..

test/misc.jl Outdated Show resolved Hide resolved
Co-authored-by: Takafumi Arakaki <[email protected]>
@IanButterworth IanButterworth merged commit 7a4b43f into JuliaLang:master Jan 11, 2022
@IanButterworth IanButterworth deleted the ib/acquire_do_syntax branch January 11, 2022 20:29
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
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