arc.rs 480 B

123456789101112131415161718192021
  1. //! This test is a more subtle one. It is one which can hit thread destructors unexpectedly.
  2. extern crate ralloc;
  3. use std::sync::Arc;
  4. use std::thread;
  5. fn main() {
  6. let numbers: Vec<_> = (0..100).collect();
  7. let shared_numbers = Arc::new(numbers);
  8. for _ in 0..10 {
  9. let child_numbers = shared_numbers.clone();
  10. thread::spawn(move || {
  11. let _local_numbers = &child_numbers[..];
  12. // Work with the local numbers
  13. });
  14. }
  15. }