55//@error-in-other-file: deadlock
66
77use std:: convert:: TryInto ;
8- use std:: thread;
98use std:: thread:: spawn;
109
1110// Using `as` cast since `EPOLLET` wraps around
@@ -41,10 +40,10 @@ fn check_epoll_wait<const N: usize>(
4140
4241// Test if only one thread is unblocked if multiple threads blocked on same epfd.
4342// Expected execution:
44- // 1. Thread 2 blocks.
45- // 2. Thread 3 blocks.
46- // 3. Thread 1 unblocks thread 3 .
47- // 4. Thread 2 deadlocks.
43+ // 1. Thread 1 blocks.
44+ // 2. Thread 2 blocks.
45+ // 3. Thread 3 unblocks thread 2 .
46+ // 4. Thread 1 deadlocks.
4847fn main ( ) {
4948 // Create an epoll instance.
5049 let epfd = unsafe { libc:: epoll_create1 ( 0 ) } ;
@@ -65,30 +64,21 @@ fn main() {
6564 let expected_value = fds[ 0 ] as u64 ;
6665 check_epoll_wait :: < 1 > ( epfd, & [ ( expected_event, expected_value) ] , 0 ) ;
6766
68- let thread1 = spawn ( move || {
69- thread:: park ( ) ;
70- let data = "abcde" . as_bytes ( ) . as_ptr ( ) ;
71- let res = unsafe { libc:: write ( fds[ 1 ] , data as * const libc:: c_void , 5 ) } ;
72- assert_eq ! ( res, 5 ) ;
73- } ) ;
74-
7567 let expected_event = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) ;
7668 let expected_value = fds[ 0 ] as u64 ;
77- let thread2 = spawn ( move || {
78- thread:: park ( ) ;
69+ let thread1 = spawn ( move || {
7970 check_epoll_wait :: < 1 > ( epfd, & [ ( expected_event, expected_value) ] , -1 ) ;
8071 //~^ERROR: deadlocked
8172 } ) ;
82- let thread3 = spawn ( move || {
83- thread:: park ( ) ;
73+ let thread2 = spawn ( move || {
8474 check_epoll_wait :: < 1 > ( epfd, & [ ( expected_event, expected_value) ] , -1 ) ;
8575 } ) ;
8676
87- thread2 . thread ( ) . unpark ( ) ;
88- thread :: yield_now ( ) ;
89- thread3 . thread ( ) . unpark ( ) ;
90- thread :: yield_now ( ) ;
91- thread1 . thread ( ) . unpark ( ) ;
77+ let thread3 = spawn ( move || {
78+ let data = "abcde" . as_bytes ( ) . as_ptr ( ) ;
79+ let res = unsafe { libc :: write ( fds [ 1 ] , data as * const libc :: c_void , 5 ) } ;
80+ assert_eq ! ( res , 5 ) ;
81+ } ) ;
9282
9383 thread1. join ( ) . unwrap ( ) ;
9484 thread2. join ( ) . unwrap ( ) ;
0 commit comments