-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement blocking eventfd #3939
Open
tiif
wants to merge
31
commits into
rust-lang:master
Choose a base branch
from
tiif:blockeventfd
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
03fb922
Add test for blocking eventfd read
tiif 0802154
Add eventfd blocking test
tiif a5cb910
Remove fail-dep test
tiif e7ffec4
Remove previously fail-dep comment
tiif 3fef8b5
Fix test error
tiif 079cd35
Add blocking support for eventfd
tiif e0485e4
Add and delete comments
tiif 70356b2
Fix rustfmt?
tiif 88d2ecd
Add test for two threads blocked on eventfd, currently deadlocked
tiif 37328f8
Fix rebase error
tiif 4574a11
Split check counter then block out of eventfd::write
tiif cffaf49
Split check value and block thread operation out of eventfd::read
tiif 73f5e46
Make blocking on several thread works
tiif 128b68c
Apply suggestion: do refcell borrow and push together
tiif 4bcc55c
Add currently failed test
tiif 9f9813e
Make block then unblock then block again works
tiif 00aea80
Add and remove comments
tiif 69543c5
Bless the test
tiif 213885b
Change name and comment
tiif 18f9e84
Add one more error annotation
tiif e5a7771
Try to make the test execution clearer by using thread::park
tiif 0d76514
Add test for read block unblock then block behaviour
tiif a9a244e
Improve tests comment
tiif 42890a9
Failed attempt to get rid of reblock
tiif d9dc134
Revert "Failed attempt to get rid of reblock"
tiif 38707e4
rustfmt
tiif 733cebc
Remove the reblock guard as it is incorrect
tiif c4abda9
Fix the BorrowMutError ICE
tiif 41ba16e
Bless the tests
tiif 64d9cfc
Remove todo
tiif e14d77e
Update comments
tiif File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,65 @@ | ||
//@only-target: linux | ||
//~^ERROR: deadlocked | ||
//~^^ERROR: deadlocked | ||
//@compile-flags: -Zmiri-preemption-rate=0 | ||
//@error-in-other-file: deadlock | ||
|
||
use std::thread; | ||
|
||
// Test the behaviour of a thread being blocked on an eventfd read, get unblocked, and then | ||
// get blocked again. | ||
|
||
// The expected execution is | ||
// 1. Thread 1 blocks. | ||
// 2. Thread 2 blocks. | ||
// 3. Thread 3 unblocks both thread 1 and thread 2. | ||
// 4. Either thread 1 or thread 2 reads. | ||
// 5. The next `read` deadlocked. | ||
|
||
fn main() { | ||
// eventfd write will block when EFD_NONBLOCK flag is clear | ||
// and the addition caused counter to exceed u64::MAX - 1. | ||
let flags = libc::EFD_CLOEXEC; | ||
let fd = unsafe { libc::eventfd(0, flags) }; | ||
|
||
let thread1 = thread::spawn(move || { | ||
thread::park(); | ||
let mut buf: [u8; 8] = [0; 8]; | ||
// This read will block initially. | ||
let res: i64 = unsafe { libc::read(fd, buf.as_mut_ptr().cast(), 8).try_into().unwrap() }; | ||
assert_eq!(res, 8); | ||
let counter = u64::from_ne_bytes(buf); | ||
assert_eq!(counter, 1_u64); | ||
}); | ||
|
||
let thread2 = thread::spawn(move || { | ||
thread::park(); | ||
let mut buf: [u8; 8] = [0; 8]; | ||
// This read will block initially, then get unblocked by thread3, then get blocked again | ||
// because the `read` in thread1 executes first and set the counter to 0 again. | ||
let res: i64 = unsafe { libc::read(fd, buf.as_mut_ptr().cast(), 8).try_into().unwrap() }; | ||
//~^ERROR: deadlocked | ||
assert_eq!(res, 8); | ||
let counter = u64::from_ne_bytes(buf); | ||
assert_eq!(counter, 1_u64); | ||
}); | ||
|
||
let thread3 = thread::spawn(move || { | ||
thread::park(); | ||
let sized_8_data = 1_u64.to_ne_bytes(); | ||
// Write 1 to the counter, so both thread1 and thread2 will unblock. | ||
let res: i64 = unsafe { | ||
libc::write(fd, sized_8_data.as_ptr() as *const libc::c_void, 8).try_into().unwrap() | ||
}; | ||
// Make sure that write is successful. | ||
assert_eq!(res, 8); | ||
}); | ||
|
||
thread1.thread().unpark(); | ||
thread2.thread().unpark(); | ||
thread3.thread().unpark(); | ||
|
||
thread1.join().unwrap(); | ||
thread2.join().unwrap(); | ||
thread3.join().unwrap(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't think of a testcase that can actually produce thread id duplication in blocked_write/read_id, but I will just keep the
dedup
here first.