Browse the docs

silk.concurrency.thread.

The normal names of the sealed thread properties Transferable and Concurrent.

When to use#

  • Bound a type parameter on Transferable when a value of it moves to another thread.

  • Bound it on Concurrent when several threads use one shared borrow of it at the same time.

  • Write impl Transferable for T {} or impl 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):

TypeTransferableConcurrent
Scalars, text, enumsYesYes
Raw pointers, Shared<T>NoNo
&TIf T is ConcurrentIf T is Concurrent
Record, union, array, closureIf every stored part isIf 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#

silk
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#

silk
pub type Transferable = Intrinsic.Transferable

The 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#

silk
pub type Concurrent = Intrinsic.Concurrent

The 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.

View the source of this page