-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #132738 - cuviper:channel-heap-init, r=ibraheemdev
Initialize channel `Block`s directly on the heap The channel's `Block::new` was causing a stack overflow because it held 32 item slots, instantiated on the stack before moving to `Box::new`. The 32x multiplier made modestly-large item sizes untenable. That block is now initialized directly on the heap. Fixes #102246 try-job: test-various
- Loading branch information
Showing
2 changed files
with
33 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//@ run-pass | ||
//@ needs-threads | ||
//@ compile-flags: -Copt-level=0 | ||
|
||
// The channel's `Block::new` was causing a stack overflow because it held 32 item slots, which is | ||
// 1MiB for this test's `BigStruct` -- instantiated on the stack before moving to `Box::new`. | ||
// | ||
// That block is now initialized directly on the heap. | ||
// | ||
// Ref: https://github.com/rust-lang/rust/issues/102246 | ||
|
||
use std::sync::mpsc::channel; | ||
use std::thread; | ||
|
||
const N: usize = 32_768; | ||
struct BigStruct { | ||
_data: [u8; N], | ||
} | ||
|
||
fn main() { | ||
let (sender, receiver) = channel::<BigStruct>(); | ||
|
||
let thread1 = thread::spawn(move || { | ||
sender.send(BigStruct { _data: [0u8; N] }).unwrap(); | ||
}); | ||
|
||
thread1.join().unwrap(); | ||
for _data in receiver.try_iter() {} | ||
} |