Skip to content

Instantly share code, notes, and snippets.

@thorseraq
Created April 24, 2023 03:56
Show Gist options
  • Select an option

  • Save thorseraq/d099ad6115ea08392284544d6ce980e4 to your computer and use it in GitHub Desktop.

Select an option

Save thorseraq/d099ad6115ea08392284544d6ce980e4 to your computer and use it in GitHub Desktop.
use std::sync::Arc;
use std::thread;
use dashmap::{DashSet};
fn main() {
let set = Arc::new(DashSet::<i32>::default());
{
for i in 0..10 {
let set = set.clone();
thread::spawn(move || {
thread::sleep(std::time::Duration::from_millis(100));
set.insert(i);
});
}
}
thread::sleep(std::time::Duration::from_millis(500));
println!("{:?}", set);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment