Created
July 16, 2022 09:00
-
-
Save pandulaDW/3d56e77531df1d48a0e9578619ff83c8 to your computer and use it in GitHub Desktop.
impl clone and drop for wg
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
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