Smithay / calloop

A callback-based Event Loop

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not all tasks scheduled with `Executor` are run

ids1024 opened this issue · comments

Not sure exactly what's going on, but some code I have trying to use calloops Executor doesn't always end up running the scheduled tasks. Adding a print to the start of the async { block shows it never starts. Using a different executor doesn't have this problem.

Here's a minimal case where I see an issue like this. It's not really reflective of exactly what I was doing where I ran into this, but it's an interesting case, where "Baz" surely should be printed, but isn't:

fn main() {
    let (executor, scheduler) = calloop::futures::executor().unwrap();
    let scheduler_clone = scheduler.clone();
    scheduler.schedule(async move {
        println!("Foo");
        scheduler_clone.schedule(async {
            println!("Bar");
        });
    });
    let mut event_loop =  calloop::EventLoop::try_new().unwrap();
    event_loop.handle().insert_source(executor, |_: (), _, _| {}).unwrap();
    event_loop.run(None::<std::time::Duration>, &mut (), |_| {
        scheduler.schedule(async {
            println!("Baz");
        });
    });
}

It looks like in both cases, removing if self.notified.swap(true, Ordering::SeqCst) { return; } fixes this. Though that logic seems reasonable. Hm.

Ah, so if schedule is called in the callback invoked by process_events, that will set notified to true (which had been cleared to false at the start of process_events, and send a ping. But the if clear_readiness { ... } block results in that ping being ignored, but doesn't set notified to false.