Skip to content

Commit a72ae75

Browse files
Tweak docs for Fiber::ExecutionContext [fixup #16135] (#16196)
Co-authored-by: Johannes Müller <[email protected]>
1 parent e071236 commit a72ae75

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/fiber/execution_context.cr

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ require "./execution_context/*"
3737
# for common use cases.
3838
#
3939
# * `ExecutionContext::Concurrent`: Fully concurrent with limited parallelism.
40-
# Fibers run concurrently, never in parallel (only one fiber at a time). They
41-
# can use simpler and faster synchronization primitives internally (no atomics,
42-
# limited thread safety). Communication with fibers in other contexts requires
43-
# thread-safe primitives. A blocking fiber blocks the entire thread and all
44-
# other fibers in the context.
40+
# Fibers run concurrently to each other, never in parallel (only one fiber at a
41+
# time). They can use simpler and faster synchronization primitives internally
42+
# (no atomics, limited thread safety). Communication with fibers in other
43+
# contexts requires thread-safe primitives. A blocking fiber blocks the entire
44+
# thread and all other fibers in the context.
4545
# * `ExecutionContext::Parallel`: Fully concurrent, fully parallel. Fibers
4646
# running in this context can be resumed by multiple system threads in this
4747
# context. They run concurrently and in parallel to each other (multiple fibers
@@ -73,6 +73,10 @@ module Fiber::ExecutionContext
7373

7474
# Returns the default `ExecutionContext` for the process, automatically
7575
# started when the program started.
76+
#
77+
# The default execution context is currently `Parallel` but only starts with
78+
# parallelism set to 1. The parallelism can be changed using
79+
# `Parallel#resize`.
7680
@[AlwaysInline]
7781
def self.default : ExecutionContext
7882
@@default.not_nil!("expected default execution context to have been setup")
@@ -163,8 +167,7 @@ module Fiber::ExecutionContext
163167
end
164168
end
165169

166-
# Creates a new fiber then calls `#enqueue` to add it to the execution
167-
# context.
170+
# Creates a new fiber then calls enqueues it to the execution context.
168171
#
169172
# May be called from any `ExecutionContext` (i.e. must be thread-safe).
170173
def spawn(*, name : String? = nil, &block : ->) : Fiber

src/fiber/execution_context/concurrent.cr

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ module Fiber::ExecutionContext
1313
# communication with fibers in other contexts requires safe primitives, for
1414
# example `Channel`.
1515
#
16-
# A blocking fiber blocks the entire context, and thus all the
17-
# other fibers in the context.
16+
# A blocking fiber blocks the entire context, and thus all the other fibers in
17+
# the context.
1818
#
1919
# For example: we can start a concurrent context to run consumer fibers, while
2020
# the default context produces values. Because the consumer fibers will never
@@ -54,14 +54,19 @@ module Fiber::ExecutionContext
5454
# variable, for example using `Atomic#add` to increment *result* or a `Mutex`
5555
# for more complex operations.
5656
class Concurrent < Parallel
57+
# :nodoc:
5758
def self.default : self
5859
new("DEFAULT", capacity: 1, hijack: true)
5960
end
6061

62+
# Creates a `Concurrent` context. The context will only really start when a
63+
# fiber is spawned into it.
6164
def self.new(name : String) : self
6265
new(name, capacity: 1, hijack: false)
6366
end
6467

68+
# Always raises an `ArgumentError` exception because a concurrent context
69+
# cannot be resized.
6570
def resize(maximum : Int32) : Nil
6671
raise ArgumentError.new("Can't resize a concurrent context")
6772
end

src/fiber/execution_context/parallel.cr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ module Fiber::ExecutionContext
7979
new("DEFAULT", maximum, hijack: true)
8080
end
8181

82-
# Starts a context with a *maximum* parallelism. The context starts with an
83-
# initial parallelism of zero. It will grow to one when a fiber is spawned,
84-
# then the actual parallelism will keep increasing and decreasing as needed,
85-
# but will never go past the configured *maximum*.
82+
# Starts a `Parallel` context with a *maximum* parallelism. The context
83+
# starts with an initial parallelism of zero. It will grow to one when a
84+
# fiber is spawned, then the actual parallelism will keep increasing and
85+
# decreasing as needed, but will never go past the configured *maximum*.
8686
def self.new(name : String, maximum : Int32) : self
8787
new(name, maximum, hijack: false)
8888
end

0 commit comments

Comments
 (0)