r/rust•
croxfo

Acquiring multiple locks in a parallel server

🙋 seeking help & advice

I have multiple task at the runtime level that access locks frequently.

select!{
  Some(req) = ch_ae.recv() => {
  match req.msg {
    Msg::AppendEntry(e) => {      
        let (mut term, logger, mut state) = {
        loop {
          if let Some(guards) = self.acquire_tls() {
            break guards;
          }
          tokio::time::interval(Duration::from_nanos(10)).tick().await;
        }
      };
  // code
 },
 // other branches
}

I am expecting "tokio::time::interval" to return control back to the executor( am I wrong here) and wait for sometime before ready to acquire locks again which may be held by other spawned tasks.
Is this a right way to acquire multiple locks.
(Each select branch awaits over an async channel.)

Posted Jul 10, 2025, 8:07 AM UTC

015

Comments aren't archived yet

This post had 15 comments on Reddit. Comments for this period haven't been loaded into the archive yet.