Skip to content

Commit ce38f08

Browse files
Seelengrabvtjnash
andauthored
Add docstring to ConcurrencyViolationError (#53733)
This should cover the current usecases of this error. --------- Co-authored-by: Sukera <[email protected]> Co-authored-by: Jameson Nash <[email protected]>
1 parent b722104 commit ce38f08

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

base/docs/basedocs.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3736,6 +3736,20 @@ The current differences are:
37363736
"""
37373737
Core.finalizer
37383738

3739+
"""
3740+
ConcurrencyViolationError(msg) <: Exception
3741+
3742+
An error thrown when a detectable violation of concurrent semantics has occurred.
3743+
3744+
A non-exhaustive list of examples of when this is used include:
3745+
3746+
* Throwing when a deadlock has been detected (e.g. `wait(current_task())`)
3747+
* Known-unsafe behavior is attempted (e.g. `yield(current_task)`)
3748+
* A known non-threadsafe datastructure is attempted to be modified from multiple concurrent tasks
3749+
* A lock is being unlocked that wasn't locked by this task
3750+
"""
3751+
ConcurrencyViolationError
3752+
37393753
Base.include(BaseDocs, "intrinsicsdocs.jl")
37403754

37413755
end

doc/src/base/parallel.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Base.istaskfailed
1313
Base.task_local_storage(::Any)
1414
Base.task_local_storage(::Any, ::Any)
1515
Base.task_local_storage(::Function, ::Any, ::Any)
16+
Core.ConcurrencyViolationError
1617
```
1718

1819
## Scheduling

doc/src/manual/multi-threading.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ julia> a
192192
Note that [`Threads.@threads`](@ref) does not have an optional reduction parameter like [`@distributed`](@ref).
193193

194194
### Using `@threads` without data-races
195+
195196
The concept of a data-race is elaborated on in ["Communication and data races between threads"](@ref man-communication-and-data-races). For now, just known that a data race can result in incorrect results and dangerous errors.
196197

197198
Lets say we want to make the function `sum_single` below multithreaded.
@@ -257,6 +258,9 @@ depending on the characteristics of the operations.
257258
Although Julia's threads can communicate through shared memory, it is notoriously difficult to write correct and data-race free multi-threaded code. Julia's
258259
[`Channel`](@ref)s are thread-safe and may be used to communicate safely. There are also sections below that explain how to use [locks](@ref man-using-locks) and [atomics](@ref man-atomic-operations) to avoid data-races.
259260

261+
In certain cases, Julia is able to detect a detect safety violations, in particular in regards to deadlocks or other known-unsafe operations such as yielding
262+
to the currently running task. In these cases, a [`ConcurrencyViolationError`](@ref) is thrown.
263+
260264
### Data-race freedom
261265

262266
You are entirely responsible for ensuring that your program is data-race free,

0 commit comments

Comments
 (0)