silk.concurrency.thread.
The normal names of the sealed thread properties Transferable and Concurrent.
When to use#
Bound a type parameter on
Transferablewhen a value of it moves to another thread.Bound it on
Concurrentwhen several threads use one shared borrow of it at the same time.Write
impl Transferable for T {}orimpl Concurrent for T {}to assert a property for a type whose stored parts cannot prove it, such as a type that owns storage through a raw pointer.
Details#
Both names are transparent type aliases (TYPE-004) of the compiler-sealed properties
Intrinsic.Transferable and Intrinsic.Concurrent (THREAD-001). The compiler derives both from
the stored parts of a type (THREAD-002):
| Type | Transferable | Concurrent |
|---|---|---|
| Scalars, text, enums | Yes | Yes |
Raw pointers, Shared<T> | No | No |
&T | If T is Concurrent | If T is Concurrent |
| Record, union, array, closure | If every stored part is | If every stored part is |
Gotchas#
An impl of either property is an unchecked assertion (THREAD-003). The compiler does not look
inside the type. The module that declares the type must synchronize the storage that the type
reaches. The impl declares no members.
Examples#
Require a value that can move to another thread#
import silk.concurrency.thread { Transferable }
struct Job {
id: i32,
}
// Accepts only values that can move to another thread.
fn handOff<T: Transferable>(value: T) -> T {
return move value
}
pub fn main() -> i32 {
let job = handOff(Job { id: 42 })
if job.id != 42 {
return 1
}
return 0
}Import as Transferable with import silk.concurrency.thread { Transferable }.
Public declarations: 2.
Transferable#
pub type Transferable = Intrinsic.TransferableThe sealed property of types whose values can move to another thread.
Details#
The compiler derives it from the stored parts of a type. Scalars, text, and enums have it. Raw
pointers and Shared<T> do not. &T has it if T is Concurrent. A record, union, array, or
closure has it if every stored part has it. Bound a type parameter on it when a value moves to
another thread.
Gotchas#
impl Transferable for T {} is an unchecked assertion. The compiler does not look inside the
type. The module that declares the type must synchronize the storage that the type reaches.
Concurrent#
pub type Concurrent = Intrinsic.ConcurrentThe sealed property of types whose shared borrows several threads can use at the same time.
Details#
The compiler derives it from the stored parts of a type. Scalars, text, and enums have it. Raw
pointers and Shared<T> do not. &T has it if T has it. A record, union, array, or closure
has it if every stored part has it.
Gotchas#
impl Concurrent for T {} is an unchecked assertion. The compiler does not look inside the
type. The module that declares the type must synchronize the storage that the type reaches.
Category: Concurrency.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.