@@ -4041,47 +4041,20 @@ let y = x;
40414041An executing Rust program consists of a tree of tasks. A Rust _ task_ consists
40424042of an entry function, a stack, a set of outgoing communication channels and
40434043incoming communication ports, and ownership of some portion of the heap of a
4044- single operating-system process. (We expect that many programs will not use
4045- channels and ports directly, but will instead use higher-level abstractions
4046- provided in standard libraries, such as pipes.)
4047-
4048- Multiple Rust tasks may coexist in a single operating-system process. The
4049- runtime scheduler maps tasks to a certain number of operating-system threads.
4050- By default, the scheduler chooses the number of threads based on the number of
4051- concurrent physical CPUs detected at startup. It's also possible to override
4052- this choice at runtime. When the number of tasks exceeds the number of threads
4053- &mdash ; which is likely &mdash ; the scheduler multiplexes the tasks onto
4054- threads.[ ^ mnscheduler ]
4055-
4056- [ ^ mnscheduler ] : This is an M: N scheduler, which is known to give suboptimal
4057- results for CPU-bound concurrency problems. In such cases, running with the
4058- same number of threads and tasks can yield better results. Rust has M: N
4059- scheduling in order to support very large numbers of tasks in contexts where
4060- threads are too resource-intensive to use in large number. The cost of
4061- threads varies substantially per operating system, and is sometimes quite
4062- low, so this flexibility is not always worth exploiting.
4044+ single operating-system process.
40634045
40644046### Communication between tasks
40654047
4066- Rust tasks are isolated and generally unable to interfere with one another's memory directly,
4067- except through [ ` unsafe ` code] ( #unsafe-functions ) .
4068- All contact between tasks is mediated by safe forms of ownership transfer,
4069- and data races on memory are prohibited by the type system.
4070-
4071- Inter-task communication and co-ordination facilities are provided in the
4072- standard library. These include:
4073-
4074- - synchronous and asynchronous communication channels with various
4075- communication topologies
4076- - read-only and read-write shared variables with various safe mutual exclusion
4077- patterns
4078- - simple locks and semaphores
4079-
4080- When such facilities carry values, the values are restricted to the [ ` Send `
4081- type-kind] ( #type-kinds ) . Restricting communication interfaces to this kind
4082- ensures that no references or managed pointers move between tasks. Thus access
4083- to an entire data structure can be mediated through its owning "root" value; no
4084- further locking or copying is required to avoid data races within the
4048+ Rust tasks are isolated and generally unable to interfere with one another's
4049+ memory directly, except through [ ` unsafe ` code] ( #unsafe-functions ) . All
4050+ contact between tasks is mediated by safe forms of ownership transfer, and data
4051+ races on memory are prohibited by the type system.
4052+
4053+ When you wish to send data between tasks, the values are restricted to the
4054+ [ ` Send ` type-kind] ( #type-kinds ) . Restricting communication interfaces to this
4055+ kind ensures that no references or managed pointers move between tasks. Thus
4056+ access to an entire data structure can be mediated through its owning "root"
4057+ value; no further locking or copying is required to avoid data races within the
40854058substructure of such a value.
40864059
40874060### Task lifecycle
@@ -4123,16 +4096,6 @@ A task in the *dead* state cannot transition to other states; it exists only to
41234096have its termination status inspected by other tasks, and/or to await
41244097reclamation when the last reference to it drops.
41254098
4126- ### Task scheduling
4127-
4128- The currently scheduled task is given a finite * time slice* in which to
4129- execute, after which it is * descheduled* at a loop-edge or similar preemption
4130- point, and another task within is scheduled, pseudo-randomly.
4131-
4132- An executing task can yield control at any time, by making a library call to
4133- ` std::task::yield ` , which deschedules it immediately. Entering any other
4134- non-executing state (blocked, dead) similarly deschedules the task.
4135-
41364099# Runtime services, linkage and debugging
41374100
41384101The Rust _ runtime_ is a relatively compact collection of C++ and Rust code that
0 commit comments