Skip to content

Commit

Permalink
Add some examples for Task related functions and Examples cleanup (Ju…
Browse files Browse the repository at this point in the history
…liaLang#46002)

* Add some examples for Task related functions and Examples cleanup

Co-authored-by: Fredrik Ekre <[email protected]>
Co-authored-by: Viral B. Shah <[email protected]>
  • Loading branch information
3 people authored Aug 26, 2022
1 parent 316fc8c commit dfbb9c4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
6 changes: 5 additions & 1 deletion base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ end
!!! compat "Julia 1.8"
Using `Base.@assume_effects` requires Julia version 1.8.
# Examples
```jldoctest
julia> Base.@assume_effects :terminates_locally function pow(x)
# this :terminates_locally allows `pow` to be constant-folded
Expand Down Expand Up @@ -874,7 +875,7 @@ the global scope or depending on mutable elements.
See [Metaprogramming](@ref) for further details.
## Example:
# Examples
```jldoctest
julia> @generated function bar(x)
if x <: Integer
Expand Down Expand Up @@ -948,6 +949,7 @@ This operation translates to a `modifyproperty!(a.b, :x, func, arg2)` call.
See [Per-field atomics](@ref man-atomics) section in the manual for more details.
# Examples
```jldoctest
julia> mutable struct Atomic{T}; @atomic x::T; end
Expand Down Expand Up @@ -1047,6 +1049,7 @@ This operation translates to a `swapproperty!(a.b, :x, new)` call.
See [Per-field atomics](@ref man-atomics) section in the manual for more details.
# Examples
```jldoctest
julia> mutable struct Atomic{T}; @atomic x::T; end
Expand Down Expand Up @@ -1093,6 +1096,7 @@ This operation translates to a `replaceproperty!(a.b, :x, expected, desired)` ca
See [Per-field atomics](@ref man-atomics) section in the manual for more details.
# Examples
```jldoctest
julia> mutable struct Atomic{T}; @atomic x::T; end
Expand Down
25 changes: 23 additions & 2 deletions base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,22 @@ const sync_varname = gensym(:sync)
"""
@sync
Wait until all lexically-enclosed uses of `@async`, `@spawn`, `@spawnat` and `@distributed`
Wait until all lexically-enclosed uses of [`@async`](@ref), [`@spawn`](@ref Threads.@spawn), `@spawnat` and `@distributed`
are complete. All exceptions thrown by enclosed async operations are collected and thrown as
a `CompositeException`.
a [`CompositeException`](@ref).
# Examples
```julia-repl
julia> Threads.nthreads()
4
julia> @sync begin
Threads.@spawn println("Thread-id \$(Threads.threadid()), task 1")
Threads.@spawn println("Thread-id \$(Threads.threadid()), task 2")
end;
Thread-id 3, task 1
Thread-id 1, task 2
```
"""
macro sync(block)
var = esc(sync_varname)
Expand Down Expand Up @@ -545,6 +558,14 @@ end
errormonitor(t::Task)
Print an error log to `stderr` if task `t` fails.
# Examples
```julia-repl
julia> Base._wait(errormonitor(Threads.@spawn error("task failed")))
Unhandled Task ERROR: task failed
Stacktrace:
[...]
```
"""
function errormonitor(t::Task)
t2 = Task() do
Expand Down

0 comments on commit dfbb9c4

Please sign in to comment.