-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📝 only static scope yield is safe (#49)
- Loading branch information
1 parent
4300d3e
commit 64e6259
Showing
5 changed files
with
66 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
fn main() { | ||
let str = "foo".to_string(); | ||
|
||
let mut gen = generator::Gn::new_scoped(|mut s| { | ||
std::thread::scope(|s2| { | ||
s2.spawn(|| { | ||
std::thread::sleep(std::time::Duration::from_millis(500)); | ||
println!("{str}"); | ||
}); | ||
// here we can't use `yield_` because it still ref to `str` | ||
// `yield_` only impl for static captured lifetime | ||
// s.yield_(()); | ||
unsafe { s.yield_unsafe(()) }; | ||
}); | ||
generator::done!(); | ||
}); | ||
|
||
gen.next(); | ||
// std::mem::forget(gen); | ||
// drop(gen); | ||
// drop(str); | ||
std::thread::sleep(std::time::Duration::from_millis(1000)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters