futures-native-timers icon indicating copy to clipboard operation
futures-native-timers copied to clipboard

timers should be `Send`

Open tinaun opened this issue 6 years ago • 3 comments

test and make sure of this.

tinaun avatar Feb 14 '19 20:02 tinaun

Hi, I was looking at the Linux implementation and I was wondering why it was explicitly made not Send. After further investigation it seems that according to the SIGNAL-SAFETY(7), it is not safe to call nonreentrant functions in signal handler. This would Mutex::lock(), I believe. I don't know, if this would cause problems with the other timer backends, but have you thought about replacing the Mutex solution with AtomicWaker (and possibly AtomicBool for done):

#[derive(Debug)]
pub (crate) struct TimerState {
    wake: AtomicWaker,
    done: AtomicBool,
}

and then simply Arc<TimerState> instead of Arc<Mutex<TimerState>>

kbleeke avatar Feb 26 '19 19:02 kbleeke

Bumped into this problem. The most important part is that the Windows impl is Send, but Linux isn't, so on my dev machine it was working but when I tried to compile it on Linux suddenly it doesn't.

PvdBerg1998 avatar Feb 28 '19 11:02 PvdBerg1998

Yea it seems like the right solution is to use AtomicWaker, which is what other event sources (like tokio and romio) all do.

withoutboats avatar Feb 28 '19 12:02 withoutboats