File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -236,6 +236,7 @@ impl<T> Channel<T> {
236
236
. compare_exchange ( block, new, Ordering :: Release , Ordering :: Relaxed )
237
237
. is_ok ( )
238
238
{
239
+ std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 2 ) ) ;
239
240
self . head . block . store ( new, Ordering :: Release ) ;
240
241
block = new;
241
242
} else {
Original file line number Diff line number Diff line change @@ -16,6 +16,28 @@ fn ms(ms: u64) -> Duration {
16
16
Duration :: from_millis ( ms)
17
17
}
18
18
19
+ #[ test]
20
+ fn gh_971 ( ) {
21
+ let ( s1, r) = unbounded :: < u64 > ( ) ;
22
+ let s2 = s1. clone ( ) ;
23
+
24
+ // This thread will sleep for 2000ms at the critical moment
25
+ let t1 = thread:: spawn ( move || assert ! ( s1. send( 42 ) . is_err( ) ) ) ;
26
+
27
+ // Give some time for thread 1 to reach the critical state
28
+ thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
29
+ // Send another value which see the tail is not null and will just advance the tail offset to 1
30
+ // and write the value.
31
+ s2. send ( 42 ) . unwrap ( ) ;
32
+
33
+ // Now drop the receiver which will attempt to drop a message by reading it since head != tail
34
+ // but head is still a null pointer because the thread t1 is still preempted leading to a
35
+ // segfault.
36
+ drop ( r) ;
37
+
38
+ t1. join ( ) . unwrap ( ) ;
39
+ }
40
+
19
41
#[ test]
20
42
fn smoke ( ) {
21
43
let ( s, r) = unbounded ( ) ;
You can’t perform that action at this time.
0 commit comments