@@ -899,8 +899,8 @@ mirrors the module hierarchy.
899
899
// Load the `vec` module from `vec.rs`
900
900
mod vec;
901
901
902
- mod task {
903
- // Load the `local_data` module from `task /local_data.rs`
902
+ mod thread {
903
+ // Load the `local_data` module from `thread /local_data.rs`
904
904
mod local_data;
905
905
}
906
906
```
@@ -909,9 +909,9 @@ The directories and files used for loading external file modules can be
909
909
influenced with the ` path ` attribute.
910
910
911
911
``` {.ignore}
912
- #[path = "task_files "]
913
- mod task {
914
- // Load the `local_data` module from `task_files /tls.rs`
912
+ #[path = "thread_files "]
913
+ mod thread {
914
+ // Load the `local_data` module from `thread_files /tls.rs`
915
915
#[path = "tls.rs"]
916
916
mod local_data;
917
917
}
@@ -1188,7 +1188,7 @@ code safe, in the surrounding context.
1188
1188
Unsafe blocks are used to wrap foreign libraries, make direct use of hardware
1189
1189
or implement features not directly present in the language. For example, Rust
1190
1190
provides the language features necessary to implement memory-safe concurrency
1191
- in the language but the implementation of tasks and message passing is in the
1191
+ in the language but the implementation of threads and message passing is in the
1192
1192
standard library.
1193
1193
1194
1194
Rust's type system is a conservative approximation of the dynamic safety
@@ -1500,7 +1500,7 @@ be modified by the program. One of Rust's goals is to make concurrency bugs
1500
1500
hard to run into, and this is obviously a very large source of race conditions
1501
1501
or other bugs. For this reason, an ` unsafe ` block is required when either
1502
1502
reading or writing a mutable static variable. Care should be taken to ensure
1503
- that modifications to a mutable static are safe with respect to other tasks
1503
+ that modifications to a mutable static are safe with respect to other threads
1504
1504
running in the same process.
1505
1505
1506
1506
Mutable statics are still very useful, however. They can be used with C
@@ -2253,11 +2253,11 @@ A complete list of the built-in language items follows:
2253
2253
* ` drop `
2254
2254
: Have destructors.
2255
2255
* ` send `
2256
- : Able to be sent across task boundaries.
2256
+ : Able to be sent across thread boundaries.
2257
2257
* ` sized `
2258
2258
: Has a size known at compile time.
2259
2259
* ` sync `
2260
- : Able to be safely shared between tasks when aliased.
2260
+ : Able to be safely shared between threads when aliased.
2261
2261
2262
2262
#### Operators
2263
2263
@@ -2621,7 +2621,7 @@ The currently implemented features of the reference compiler are:
2621
2621
LLVM's implementation which works in concert with the kernel
2622
2622
loader and dynamic linker. This is not necessarily available
2623
2623
on all platforms, and usage of it is discouraged (rust
2624
- focuses more on task -local data instead of thread-local
2624
+ focuses more on thread -local data instead of thread-local
2625
2625
data).
2626
2626
2627
2627
* ` trace_macros ` - Allows use of the ` trace_macros ` macro, which is a nasty
@@ -2939,7 +2939,7 @@ array is mutable, the resulting [lvalue](#lvalues,-rvalues-and-temporaries) can
2939
2939
be assigned to.
2940
2940
2941
2941
Indices are zero-based, and may be of any integral type. Vector access is
2942
- bounds-checked at run-time. When the check fails, it will put the task in a
2942
+ bounds-checked at run-time. When the check fails, it will put the thread in a
2943
2943
_ panicked state_ .
2944
2944
2945
2945
``` {should-fail}
@@ -3950,7 +3950,7 @@ Types in Rust are categorized into kinds, based on various properties of the
3950
3950
components of the type. The kinds are:
3951
3951
3952
3952
* ` Send `
3953
- : Types of this kind can be safely sent between tasks .
3953
+ : Types of this kind can be safely sent between threads .
3954
3954
This kind includes scalars, boxes, procs, and
3955
3955
structural types containing only other owned types.
3956
3956
All ` Send ` types are ` 'static ` .
@@ -3998,21 +3998,21 @@ to sendable.
3998
3998
3999
3999
# Memory and concurrency models
4000
4000
4001
- Rust has a memory model centered around concurrently-executing _ tasks _ . Thus
4001
+ Rust has a memory model centered around concurrently-executing _ threads _ . Thus
4002
4002
its memory model and its concurrency model are best discussed simultaneously,
4003
4003
as parts of each only make sense when considered from the perspective of the
4004
4004
other.
4005
4005
4006
4006
When reading about the memory model, keep in mind that it is partitioned in
4007
- order to support tasks ; and when reading about tasks , keep in mind that their
4007
+ order to support threads ; and when reading about threads , keep in mind that their
4008
4008
isolation and communication mechanisms are only possible due to the ownership
4009
4009
and lifetime semantics of the memory model.
4010
4010
4011
4011
## Memory model
4012
4012
4013
4013
A Rust program's memory consists of a static set of * items* , a set of
4014
- [ tasks ] ( #tasks ) each with its own * stack* , and a * heap* . Immutable portions of
4015
- the heap may be shared between tasks , mutable portions may not.
4014
+ [ threads ] ( #threads ) each with its own * stack* , and a * heap* . Immutable portions of
4015
+ the heap may be shared between threads , mutable portions may not.
4016
4016
4017
4017
Allocations in the stack consist of * slots* , and allocations in the heap
4018
4018
consist of * boxes* .
@@ -4023,8 +4023,8 @@ The _items_ of a program are those functions, modules and types that have their
4023
4023
value calculated at compile-time and stored uniquely in the memory image of the
4024
4024
rust process. Items are neither dynamically allocated nor freed.
4025
4025
4026
- A task 's _ stack_ consists of activation frames automatically allocated on entry
4027
- to each function as the task executes. A stack allocation is reclaimed when
4026
+ A thread 's _ stack_ consists of activation frames automatically allocated on entry
4027
+ to each function as the thread executes. A stack allocation is reclaimed when
4028
4028
control leaves the frame containing it.
4029
4029
4030
4030
The _ heap_ is a general term that describes boxes. The lifetime of an
@@ -4034,10 +4034,10 @@ in the heap, heap allocations may outlive the frame they are allocated within.
4034
4034
4035
4035
### Memory ownership
4036
4036
4037
- A task owns all memory it can * safely* reach through local variables, as well
4037
+ A thread owns all memory it can * safely* reach through local variables, as well
4038
4038
as boxes and references.
4039
4039
4040
- When a task sends a value that has the ` Send ` trait to another task , it loses
4040
+ When a thread sends a value that has the ` Send ` trait to another thread , it loses
4041
4041
ownership of the value sent and can no longer refer to it. This is statically
4042
4042
guaranteed by the combined use of "move semantics", and the compiler-checked
4043
4043
_ meaning_ of the ` Send ` trait: it is only instantiated for (transitively)
@@ -4046,12 +4046,12 @@ sendable kinds of data constructor and pointers, never including references.
4046
4046
When a stack frame is exited, its local allocations are all released, and its
4047
4047
references to boxes are dropped.
4048
4048
4049
- When a task finishes, its stack is necessarily empty and it therefore has no
4049
+ When a thread finishes, its stack is necessarily empty and it therefore has no
4050
4050
references to any boxes; the remainder of its heap is immediately freed.
4051
4051
4052
4052
### Memory slots
4053
4053
4054
- A task 's stack contains slots.
4054
+ A thread 's stack contains slots.
4055
4055
4056
4056
A _ slot_ is a component of a stack frame, either a function parameter, a
4057
4057
[ temporary] ( #lvalues,-rvalues-and-temporaries ) , or a local variable.
@@ -4105,72 +4105,69 @@ let y = x;
4105
4105
// attempting to use `x` will result in an error here
4106
4106
```
4107
4107
4108
- ## Tasks
4108
+ ## Threads
4109
4109
4110
- An executing Rust program consists of a tree of tasks. A Rust _ task_ consists
4111
- of an entry function, a stack, a set of outgoing communication channels and
4112
- incoming communication ports, and ownership of some portion of the heap of a
4113
- single operating-system process.
4110
+ Rust's primary concurrency mechanism is called a ** thread** .
4114
4111
4115
- ### Communication between tasks
4112
+ ### Communication between threads
4116
4113
4117
- Rust tasks are isolated and generally unable to interfere with one another's
4114
+ Rust threads are isolated and generally unable to interfere with one another's
4118
4115
memory directly, except through [ ` unsafe ` code] ( #unsafe-functions ) . All
4119
- contact between tasks is mediated by safe forms of ownership transfer, and data
4116
+ contact between threads is mediated by safe forms of ownership transfer, and data
4120
4117
races on memory are prohibited by the type system.
4121
4118
4122
- When you wish to send data between tasks , the values are restricted to the
4119
+ When you wish to send data between threads , the values are restricted to the
4123
4120
[ ` Send ` type-kind] ( #type-kinds ) . Restricting communication interfaces to this
4124
- kind ensures that no references move between tasks . Thus access to an entire
4121
+ kind ensures that no references move between threads . Thus access to an entire
4125
4122
data structure can be mediated through its owning "root" value; no further
4126
4123
locking or copying is required to avoid data races within the substructure of
4127
4124
such a value.
4128
4125
4129
- ### Task lifecycle
4126
+ ### Thread
4130
4127
4131
- The _ lifecycle_ of a task consists of a finite set of states and events that
4132
- cause transitions between the states. The lifecycle states of a task are:
4128
+ The _ lifecycle_ of a threads consists of a finite set of states and events that
4129
+ cause transitions between the states. The lifecycle states of a thread are:
4133
4130
4134
4131
* running
4135
4132
* blocked
4136
4133
* panicked
4137
4134
* dead
4138
4135
4139
- A task begins its lifecycle &mdash ; once it has been spawned &mdash ; in the
4136
+ A thread begins its lifecycle &mdash ; once it has been spawned &mdash ; in the
4140
4137
* running* state. In this state it executes the statements of its entry
4141
4138
function, and any functions called by the entry function.
4142
4139
4143
- A task may transition from the * running* state to the * blocked* state any time
4140
+ A thread may transition from the * running* state to the * blocked* state any time
4144
4141
it makes a blocking communication call. When the call can be completed &mdash ;
4145
4142
when a message arrives at a sender, or a buffer opens to receive a message
4146
- &mdash ; then the blocked task will unblock and transition back to * running* .
4143
+ &mdash ; then the blocked thread will unblock and transition back to * running* .
4147
4144
4148
- A task may transition to the * panicked* state at any time, due being killed by
4145
+ A thread may transition to the * panicked* state at any time, due being killed by
4149
4146
some external event or internally, from the evaluation of a ` panic!() ` macro.
4150
- Once * panicking* , a task unwinds its stack and transitions to the * dead* state.
4151
- Unwinding the stack of a task is done by the task itself, on its own control
4147
+ Once * panicking* , a thread unwinds its stack and transitions to the * dead* state.
4148
+ Unwinding the stack of a thread is done by the thread itself, on its own control
4152
4149
stack. If a value with a destructor is freed during unwinding, the code for the
4153
- destructor is run, also on the task 's control stack. Running the destructor
4150
+ destructor is run, also on the thread 's control stack. Running the destructor
4154
4151
code causes a temporary transition to a * running* state, and allows the
4155
- destructor code to cause any subsequent state transitions. The original task
4152
+ destructor code to cause any subsequent state transitions. The original thread
4156
4153
of unwinding and panicking thereby may suspend temporarily, and may involve
4157
4154
(recursive) unwinding of the stack of a failed destructor. Nonetheless, the
4158
4155
outermost unwinding activity will continue until the stack is unwound and the
4159
- task transitions to the * dead* state. There is no way to "recover" from task
4160
- panics. Once a task has temporarily suspended its unwinding in the * panicking*
4156
+ thread transitions to the * dead* state. There is no way to "recover" from thread
4157
+ panics. Once a thread has temporarily suspended its unwinding in the * panicking*
4161
4158
state, a panic occurring from within this destructor results in * hard* panic.
4162
4159
A hard panic currently results in the process aborting.
4163
4160
4164
- A task in the * dead* state cannot transition to other states; it exists only to
4165
- have its termination status inspected by other tasks , and/or to await
4161
+ A thread in the * dead* state cannot transition to other states; it exists only to
4162
+ have its termination status inspected by other threads , and/or to await
4166
4163
reclamation when the last reference to it drops.
4167
4164
4168
4165
# Runtime services, linkage and debugging
4169
4166
4170
4167
The Rust _ runtime_ is a relatively compact collection of Rust code that
4171
- provides fundamental services and datatypes to all Rust tasks at run-time. It
4168
+ provides fundamental services and datatypes to all Rust threads at run-time. It
4172
4169
is smaller and simpler than many modern language runtimes. It is tightly
4173
- integrated into the language's execution model of memory, tasks , communication
4170
+ integrated into the language's execution model of memory, threads , communication
4174
4171
and logging.
4175
4172
4176
4173
### Memory allocation
@@ -4181,23 +4178,23 @@ environment and releases them back to its environment when they are no longer
4181
4178
needed. The default implementation of the service-provider interface consists
4182
4179
of the C runtime functions ` malloc ` and ` free ` .
4183
4180
4184
- The runtime memory-management system, in turn, supplies Rust tasks with
4181
+ The runtime memory-management system, in turn, supplies Rust threads with
4185
4182
facilities for allocating releasing stacks, as well as allocating and freeing
4186
4183
heap data.
4187
4184
4188
4185
### Built in types
4189
4186
4190
4187
The runtime provides C and Rust code to assist with various built-in types,
4191
4188
such as arrays, strings, and the low level communication system (ports,
4192
- channels, tasks ).
4189
+ channels, threads ).
4193
4190
4194
4191
Support for other built-in types such as simple types, tuples and enums is
4195
4192
open-coded by the Rust compiler.
4196
4193
4197
- ### Task scheduling and communication
4194
+ ### Thread scheduling and communication
4198
4195
4199
- The runtime provides code to manage inter-task communication. This includes
4200
- the system of task -lifecycle state transitions depending on the contents of
4196
+ The runtime provides code to manage inter-thread communication. This includes
4197
+ the system of thread -lifecycle state transitions depending on the contents of
4201
4198
queues, as well as code to copy values between queues and their recipients and
4202
4199
to serialize values for transmission over operating-system inter-process
4203
4200
communication facilities.
0 commit comments