rollup merge of #20988: ciphergoth/task-to-thread
"Tasks" are no longer a thing in Rust; refer to threads instead. Work is still needed on [threads.md](threads.md).
This commit is contained in:
commit
c478c6ac91
6 changed files with 13 additions and 14 deletions
|
@ -26,7 +26,7 @@
|
||||||
* [Iterators](iterators.md)
|
* [Iterators](iterators.md)
|
||||||
* [Generics](generics.md)
|
* [Generics](generics.md)
|
||||||
* [Traits](traits.md)
|
* [Traits](traits.md)
|
||||||
* [Tasks](tasks.md)
|
* [Threads](threads.md)
|
||||||
* [Error Handling](error-handling.md)
|
* [Error Handling](error-handling.md)
|
||||||
* [III: Advanced Topics](advanced.md)
|
* [III: Advanced Topics](advanced.md)
|
||||||
* [FFI](ffi.md)
|
* [FFI](ffi.md)
|
||||||
|
|
|
@ -181,7 +181,7 @@ errors that can occur.
|
||||||
# Non-recoverable errors with `panic!`
|
# Non-recoverable errors with `panic!`
|
||||||
|
|
||||||
In the case of an error that is unexpected and not recoverable, the `panic!`
|
In the case of an error that is unexpected and not recoverable, the `panic!`
|
||||||
macro will induce a panic. This will crash the current task, and give an error:
|
macro will induce a panic. This will crash the current thread, and give an error:
|
||||||
|
|
||||||
```{rust,ignore}
|
```{rust,ignore}
|
||||||
panic!("boom");
|
panic!("boom");
|
||||||
|
@ -190,7 +190,7 @@ panic!("boom");
|
||||||
gives
|
gives
|
||||||
|
|
||||||
```text
|
```text
|
||||||
task '<main>' panicked at 'boom', hello.rs:2
|
thread '<main>' panicked at 'boom', hello.rs:2
|
||||||
```
|
```
|
||||||
|
|
||||||
when you run it.
|
when you run it.
|
||||||
|
|
|
@ -166,12 +166,12 @@ GitHub](https://github.com/thestinger/rust-snappy).
|
||||||
|
|
||||||
# Stack management
|
# Stack management
|
||||||
|
|
||||||
Rust tasks by default run on a *large stack*. This is actually implemented as a
|
Rust threads by default run on a *large stack*. This is actually implemented as a
|
||||||
reserving a large segment of the address space and then lazily mapping in pages
|
reserving a large segment of the address space and then lazily mapping in pages
|
||||||
as they are needed. When calling an external C function, the code is invoked on
|
as they are needed. When calling an external C function, the code is invoked on
|
||||||
the same stack as the rust stack. This means that there is no extra
|
the same stack as the rust stack. This means that there is no extra
|
||||||
stack-switching mechanism in place because it is assumed that the large stack
|
stack-switching mechanism in place because it is assumed that the large stack
|
||||||
for the rust task is plenty for the C function to have.
|
for the rust thread is plenty for the C function to have.
|
||||||
|
|
||||||
A planned future improvement (not yet implemented at the time of this writing)
|
A planned future improvement (not yet implemented at the time of this writing)
|
||||||
is to have a guard page at the end of every rust stack. No rust function will
|
is to have a guard page at the end of every rust stack. No rust function will
|
||||||
|
@ -184,8 +184,8 @@ For normal external function usage, this all means that there shouldn't be any
|
||||||
need for any extra effort on a user's perspective. The C stack naturally
|
need for any extra effort on a user's perspective. The C stack naturally
|
||||||
interleaves with the rust stack, and it's "large enough" for both to
|
interleaves with the rust stack, and it's "large enough" for both to
|
||||||
interoperate. If, however, it is determined that a larger stack is necessary,
|
interoperate. If, however, it is determined that a larger stack is necessary,
|
||||||
there are appropriate functions in the task spawning API to control the size of
|
there are appropriate functions in the thread spawning API to control the size of
|
||||||
the stack of the task which is spawned.
|
the stack of the thread which is spawned.
|
||||||
|
|
||||||
# Destructors
|
# Destructors
|
||||||
|
|
||||||
|
@ -320,8 +320,7 @@ In the previously given examples the callbacks are invoked as a direct reaction
|
||||||
to a function call to the external C library.
|
to a function call to the external C library.
|
||||||
The control over the current thread is switched from Rust to C to Rust for the
|
The control over the current thread is switched from Rust to C to Rust for the
|
||||||
execution of the callback, but in the end the callback is executed on the
|
execution of the callback, but in the end the callback is executed on the
|
||||||
same thread (and Rust task) that lead called the function which triggered
|
same thread that called the function which triggered the callback.
|
||||||
the callback.
|
|
||||||
|
|
||||||
Things get more complicated when the external library spawns its own threads
|
Things get more complicated when the external library spawns its own threads
|
||||||
and invokes callbacks from there.
|
and invokes callbacks from there.
|
||||||
|
@ -329,7 +328,7 @@ In these cases access to Rust data structures inside the callbacks is
|
||||||
especially unsafe and proper synchronization mechanisms must be used.
|
especially unsafe and proper synchronization mechanisms must be used.
|
||||||
Besides classical synchronization mechanisms like mutexes, one possibility in
|
Besides classical synchronization mechanisms like mutexes, one possibility in
|
||||||
Rust is to use channels (in `std::comm`) to forward data from the C thread
|
Rust is to use channels (in `std::comm`) to forward data from the C thread
|
||||||
that invoked the callback into a Rust task.
|
that invoked the callback into a Rust thread.
|
||||||
|
|
||||||
If an asynchronous callback targets a special object in the Rust address space
|
If an asynchronous callback targets a special object in the Rust address space
|
||||||
it is also absolutely necessary that no more callbacks are performed by the
|
it is also absolutely necessary that no more callbacks are performed by the
|
||||||
|
|
|
@ -96,7 +96,7 @@ test it_works ... FAILED
|
||||||
failures:
|
failures:
|
||||||
|
|
||||||
---- it_works stdout ----
|
---- it_works stdout ----
|
||||||
task 'it_works' panicked at 'assertion failed: false', /home/steve/tmp/adder/src/lib.rs:3
|
thread 'it_works' panicked at 'assertion failed: false', /home/steve/tmp/adder/src/lib.rs:3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ failures:
|
||||||
|
|
||||||
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
|
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
|
||||||
|
|
||||||
task '<main>' panicked at 'Some tests failed', /home/steve/src/rust/src/libtest/lib.rs:247
|
thread '<main>' panicked at 'Some tests failed', /home/steve/src/rust/src/libtest/lib.rs:247
|
||||||
```
|
```
|
||||||
|
|
||||||
Rust indicates that our test failed:
|
Rust indicates that our test failed:
|
||||||
|
|
|
@ -182,7 +182,7 @@ code:
|
||||||
- implement the `Drop` for resource clean-up via a destructor, and use
|
- implement the `Drop` for resource clean-up via a destructor, and use
|
||||||
RAII (Resource Acquisition Is Initialization). This reduces the need
|
RAII (Resource Acquisition Is Initialization). This reduces the need
|
||||||
for any manual memory management by users, and automatically ensures
|
for any manual memory management by users, and automatically ensures
|
||||||
that clean-up is always run, even when the task panics.
|
that clean-up is always run, even when the thread panics.
|
||||||
- ensure that any data stored behind a raw pointer is destroyed at the
|
- ensure that any data stored behind a raw pointer is destroyed at the
|
||||||
appropriate time.
|
appropriate time.
|
||||||
|
|
||||||
|
@ -499,7 +499,7 @@ library, but without it you must define your own.
|
||||||
The first of these three functions, `stack_exhausted`, is invoked whenever stack
|
The first of these three functions, `stack_exhausted`, is invoked whenever stack
|
||||||
overflow is detected. This function has a number of restrictions about how it
|
overflow is detected. This function has a number of restrictions about how it
|
||||||
can be called and what it must do, but if the stack limit register is not being
|
can be called and what it must do, but if the stack limit register is not being
|
||||||
maintained then a task always has an "infinite stack" and this function
|
maintained then a thread always has an "infinite stack" and this function
|
||||||
shouldn't get triggered.
|
shouldn't get triggered.
|
||||||
|
|
||||||
The second of these three functions, `eh_personality`, is used by the
|
The second of these three functions, `eh_personality`, is used by the
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue