It sounds like you're referring to (the educational OS kernel written in Rust, often used in Tsinghua University’s OS courses) and gangs in the context of parallel computing or OS process groups (e.g., gang scheduling).
pub struct GangScheduler gangs: BTreeMap<usize, Arc<Mutex<Gang>>>, task_to_gang: BTreeMap<usize, usize>, ready_gangs: VecDeque<usize>, // queue of gang IDs ready to run
pub fn create_gang(&mut self, members: Vec<usize>) -> usize let id = self.gangs.len(); let gang = Arc::new(Mutex::new(Gang id, members: members.clone(), status: GangStatus::Pending, )); for &tid in &members self.task_to_gang.insert(tid, id); self.gangs.insert(id, gang); id
impl GangScheduler pub fn new() -> Self Self gangs: BTreeMap::new(), task_to_gang: BTreeMap::new(), ready_gangs: VecDeque::new(),
Modify your existing scheduler (e.g., RoundRobinScheduler ) to wrap gang logic:
/// Pick the next runnable gang, then return its next member to run pub fn pick_next_task(&mut self) -> Option<usize> while let Some(gang_id) = self.ready_gangs.pop_front() let gang = self.gangs.get(&gang_id).unwrap(); let mut gang_lock = gang.lock(); if gang_lock.status == GangStatus::Runnable gang_lock.status = GangStatus::Running; // Return the first member that isn't already running on a CPU for &tid in &gang_lock.members if !is_task_running_on_another_cpu(tid) return Some(tid); // If all already running (rare), re-queue self.ready_gangs.push_back(gang_id); None
/// Called when a task yields or blocks pub fn task_blocked(&mut self, tid: usize) if let Some(&gang_id) = self.task_to_gang.get(&tid) let gang = self.gangs.get(&gang_id).unwrap(); let mut gang_lock = gang.lock(); gang_lock.status = GangStatus::Pending; // Optionally, preempt all other members of this gang for &other in &gang_lock.members if other != tid && task_status(other) == TaskStatus::Running force_yield_task(other);
pub struct HybridScheduler inner: RoundRobinScheduler, gang_sched: GangScheduler,