Skip to content

It is recommended that threads support context transfer and automatically perform clone operations #133795

Closed as duplicate of#107
@1057105012

Description

@1057105012

Code

fn main() {
    let (sx, rx) = mpsc::channel();
    let handle = thread::spawn(move |sx, rx| {
        sx.send("hello").unwrap();
    });
    handle.join().unwrap();
}

It is recommended that threads support context. As shown in the figure, the context automatically performs cloning operations, which can avoid code, like this let handle = thread::spawn(move |sx, rx| {} not sx.clone(), rx.clone()。 

This operation can be understood as opening an isolation domain. Or abstract it into a more general concept. Rust allows the creation of isolated domains. All external borrowing in the isolation domain is automatically recognized as a clone operation

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions