Browse Source

Checking if we can move references into threads

master
Julio Biason 2 years ago
parent
commit
37dd6fda59
  1. 7
      movereftest/Cargo.lock
  2. 8
      movereftest/Cargo.toml
  3. 3
      movereftest/README.md
  4. 22
      movereftest/src/main.rs

7
movereftest/Cargo.lock generated

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "movereftest"
version = "0.1.0"

8
movereftest/Cargo.toml

@ -0,0 +1,8 @@
[package]
name = "movereftest"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

3
movereftest/README.md

@ -0,0 +1,3 @@
# MoveRefTest
Testing if one can move the reference withtout moving the real data.

22
movereftest/src/main.rs

@ -0,0 +1,22 @@
use std::thread;
fn main() {
let concrete = String::from("Hello!");
let ref1 = &concrete;
let t1 = thread::spawn(move || {
for i in 0..5 {
println!("Thread1: {} - {}", i, ref1);
}
});
let ref2 = &concrete;
let t2 = thread::spawn(move || {
for i in 5..10 {
println!("Thread2: {} - {}", i, ref2);
}
});
t1.join();
t2.join();
}
Loading…
Cancel
Save