Content deleted Content added
Add Rust |
|||
Line 13:
===libthread channels===
The [[Multithreading (computer architecture)|
===OCaml events===
Line 43:
x := <- c
</syntaxhighlight>
=== Rust ===
[[Rust (programming language)|Rust]] provides asynchronous channels for communication between threads. Channels allow a unidirectional flow of information between two end-points: the <code>Sender</code> and the <code>Receiver</code>.<ref>{{cite web |title=Channels - Rust By Example |url=https://doc.rust-lang.org/rust-by-example/std_misc/channels.html |website=doc.rust-lang.org |access-date=28 November 2020}}</ref>
<syntaxhighlight lang="rust">
use std::sync::mpsc;
use std::thread;
fn main() {
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
tx.send(123).unwrap();
});
let result = rx.recv();
println!("{:?}", result);
}
</syntaxhighlight>
|