arc.rs 574 B

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