Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion base/lock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -933,4 +933,6 @@ mutable struct OncePerTask{T, F} <: Function
OncePerTask{T,F}(initializer::F) where {T, F} = new{T,F}(initializer)
OncePerTask(initializer) = new{Base.promote_op(initializer), typeof(initializer)}(initializer)
end
@inline (once::OncePerTask)() = get!(once.initializer, task_local_storage(), once)
@inline function (once::OncePerTask{T})() where {T}
get!(once.initializer, task_local_storage(), once)::T
end
8 changes: 4 additions & 4 deletions test/threads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ end

let once = OncePerProcess(() -> return [nothing])
@test typeof(once) <: OncePerProcess{Vector{Nothing}}
x = once()
x = @inferred once()
@test x === once()
@atomic once.state = 0xff
@test_throws ErrorException("invalid state for OncePerProcess") once()
Expand All @@ -456,7 +456,7 @@ let e = Base.Event(true),
started = Channel{Int16}(Inf),
finish = Channel{Nothing}(Inf),
exiting = Channel{Nothing}(Inf),
starttest2 = Event(),
starttest2 = Base.Event(),
once = OncePerThread() do
push!(started, threadid())
take!(finish)
Expand All @@ -468,7 +468,7 @@ let e = Base.Event(true),
@test typeof(once) <: OncePerThread{Vector{Nothing}}
push!(finish, nothing)
@test_throws ArgumentError once[0]
x = once()
x = @inferred once()
@test_throws ArgumentError once[0]
@test x === once() === fetch(@async once()) === once[threadid()]
@test take!(started) == threadid()
Expand Down Expand Up @@ -558,7 +558,7 @@ end

let once = OncePerTask(() -> return [nothing])
@test typeof(once) <: OncePerTask{Vector{Nothing}}
x = once()
x = @inferred once()
@test x === once() !== fetch(@async once())
delete!(task_local_storage(), once)
@test x !== once() === once()
Expand Down