Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/uu/pgrep/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,15 +902,25 @@ unknown /dev/tty 4 1-63 console"#;
#[test]
#[cfg(target_os = "linux")]
fn test_thread_ids() {
let main_tid = rustix::thread::gettid().as_raw_nonzero().get() as u64;
let main_tid = rustix::thread::gettid().as_raw_nonzero().get() as usize;
std::thread::spawn(move || {
let mut pid_entry = ProcessInformation::current_process_info().unwrap();
let thread_ids = pid_entry.thread_ids();

assert!(thread_ids.contains(&(main_tid as usize)));

let new_thread_tid = rustix::thread::gettid().as_raw_nonzero().get() as u64;
assert!(thread_ids.contains(&(new_thread_tid as usize)));
let new_thread_tid = rustix::thread::gettid().as_raw_nonzero().get() as usize;
// /proc/<pid>/task can lag a newly started thread, and a single

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it really a lag? the thread is already running when it reads its own task dir
i think it is more readdir skipping entries while other test threads exit concurrently, could you please reword?

// WalkDir snapshot may miss it (https://github.com/uutils/procps/issues/471).
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(2);
loop {
let mut pid_entry = ProcessInformation::current_process_info().unwrap();
let thread_ids = pid_entry.thread_ids();
if thread_ids.contains(&main_tid) && thread_ids.contains(&new_thread_tid) {
return;
}
if std::time::Instant::now() >= deadline {
panic!(
"thread_ids missing main {main_tid} or new {new_thread_tid}: {thread_ids:?}"
);
}
std::thread::sleep(std::time::Duration::from_millis(5));
}
})
.join()
.unwrap();
Expand Down
Loading