-
Notifications
You must be signed in to change notification settings - Fork 24
Closed
Description
use std::{mem::forget, sync::mpsc};
use corosensei::ScopedCoroutine;
fn main() {
let mut s = "Happy".to_owned();
let (tx1, rx1) = mpsc::sync_channel(1);
let (tx2, rx2) = mpsc::sync_channel(1);
{
let s = s.as_str();
let mut coroutine = Box::pin(ScopedCoroutine::new(|yielder, ()| {
std::thread::scope(move |scope| {
let _thrd = scope.spawn(move || {
rx1.recv().unwrap();
tx2.send(s.to_owned()).unwrap();
});
let () = yielder.suspend(());
});
}));
coroutine.as_mut().resume(());
forget(coroutine);
}
s.clear();
s.push_str("Sad");
tx1.send(()).unwrap();
let data_race_s = rx2.recv().unwrap();
dbg!(&s, &data_race_s);
}Prints out:
[src/main.rs:27:5] &s = "Sad"
[src/main.rs:27:5] &data_race_s = "Sadpy"
Metadata
Metadata
Assignees
Labels
No labels