Skip to content

Instantly share code, notes, and snippets.

@pandulaDW
Created July 16, 2022 09:00
Show Gist options
  • Save pandulaDW/3d56e77531df1d48a0e9578619ff83c8 to your computer and use it in GitHub Desktop.
Save pandulaDW/3d56e77531df1d48a0e9578619ff83c8 to your computer and use it in GitHub Desktop.
impl clone and drop for wg
impl Clone for WaitGroup {
fn clone(&self) -> Self {
self.0.counter.fetch_add(1, Ordering::Relaxed);
Self(self.0.clone())
}
}
impl Drop for WaitGroup {
fn drop(&mut self) {
self.0.counter.fetch_sub(1, Ordering::Relaxed);
self.0.condvar.notify_one();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment