Skip to content
Merged
Changes from all commits
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
20 changes: 15 additions & 5 deletions tests/ui/std/channel-stack-overflow-issue-102246.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,30 @@
// Ref: https://github.com/rust-lang/rust/issues/102246

use std::sync::mpsc::channel;
use std::thread;
use std::thread::Builder;

const N: usize = 32_768;
const SLOTS: usize = 32;
// Use a stack size that's smaller than N * SLOTS, proving the allocation is on the heap.
//
// The test explicitly specifies the stack size, because not all platforms have the same default
// size.
const STACK_SIZE: usize = (N*SLOTS) - 1;

struct BigStruct {
_data: [u8; N],
}

fn main() {
let (sender, receiver) = channel::<BigStruct>();

let thread1 = thread::spawn(move || {
let thread1 = Builder::new().stack_size(STACK_SIZE).spawn(move || {
sender.send(BigStruct { _data: [0u8; N] }).unwrap();
});

}).expect("thread1 should spawn successfully");
thread1.join().unwrap();
for _data in receiver.try_iter() {}

let thread2 = Builder::new().stack_size(STACK_SIZE).spawn(move || {
for _data in receiver.try_iter() {}
}).expect("thread2 should spawn successfully");
thread2.join().unwrap();
}
Loading