-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow unblocking of non-subscribed signals
- It is possible to block only those signals that are passed as parameters to notify/notify_on in the main thread and all threads spawned later. - In order not to change the default behavior, all subscribable signals are still blocked by default. The new behavior can be opted into by calling the new function unblock_signals_by_default before notify/notify_on.
- Loading branch information
1 parent
af64d8a
commit 8207219
Showing
2 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#[macro_use] | ||
extern crate chan; | ||
extern crate chan_signal; | ||
|
||
use chan_signal::{Signal, kill_this}; | ||
|
||
fn main() { | ||
chan_signal::unblock_signals_by_default(); | ||
let r_usr1 = chan_signal::notify(&[Signal::USR1]); | ||
kill_this(Signal::USR1); | ||
assert_eq!(r_usr1.recv(), Some(Signal::USR1)); | ||
|
||
let (s, r_usr2) = chan::sync(1); | ||
chan_signal::notify_on(&s, Signal::USR2); | ||
kill_this(Signal::USR2); | ||
assert_eq!(r_usr2.recv(), Some(Signal::USR2)); | ||
|
||
// The following will terminate the process, as it is NOT blocked | ||
// by the main thread. | ||
kill_this(Signal::TERM); | ||
unreachable!(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters