Select and implement synchronization primitives that match your concurrency requirements and avoid unsafe patterns. Consider the number of consumers, thread safety requirements, and proper initialization order.

Key guidelines:

Example of correct async flag implementation:

impl AsyncFlag {
  pub fn raise(&self) {
    self.0.add_permits(1);  // Preserve semaphore state
  }

  pub async fn wait_raised(&self) {
    drop(self.0.acquire().await);  // Proper waiting mechanism
  }
}

Avoid unsafe patterns like direct environment modification in multi-threaded contexts, and ensure synchronization primitives maintain proper ordering and state consistency throughout their lifecycle.