Comments (2)
rand
is using a big stack size in it's implementation.
for debug version stack usage
coroutine name = None, stack size = 40959, used size = 9205
for release version
coroutine name = None, stack size = 40959, used size = 2740
here is the modified test
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate may;
extern crate rand;
use std::io::Read;
use std::collections::HashMap;
// the ThreadRng is using a big stack!
lazy_static! {
static ref DATA: Vec<u8> = vec![rand::random::<u8>()];
}
// the OsRng is not using a big stack, you can safely use it in coroutine context
/*
lazy_static! {
static ref DATA: Vec<u8> = {
use rand::Rng;
let mut rand = rand::OsRng::new().unwrap();
vec![rand.gen()]
};
}
*/
fn main() {
may::config().set_stack_size(4096*10 - 1);
let mut entries: HashMap<usize, Vec<u8>> = HashMap::new();
// force init DATA in the main thread
// let _ = DATA[0];
let task = go!(move || {
entries.insert(0, DATA.clone());
});
task.join().unwrap();
std::io::stdin().read(&mut [0]).ok();
}
the solution is init the DATA
in main thread (not in the coroutine context, just like what you did to pass the test), or use the os rand interface which doesn't use a huge stack.
from may.
Now it makes perfect sense. Static values declared with lazy_static!
only get evaluated once the value is used, that's why lazy
(d'oh), and if it's being used inside the coroutine context it also affect's it's stack. I'm such a noob.
Thanks for your time and patience!
from may.
Related Issues (20)
- support cancel feature gate
- 关于文档
- Is it safe to use `may::sync::Mutex` in non-coroutine context? HOT 2
- Feature request: Stop-the-world mechanism HOT 1
- Any plans supporting ARM on linux? HOT 2
- New features,Automatic processing of heavy CPU or blocking IO tasks HOT 1
- There is no IO API for File open,write....?
- question: way not generator-rs Stack resizes automatically? HOT 4
- Queue needs bounds on its Send/Sync traits HOT 2
- Examples don't compile HOT 2
- about performace.md The description is unfair HOT 3
- 建议参考ants,整个协程池
- `may_http`耗时不符合预期 HOT 5
- 建议参考libco,hook系统函数,减少改造成本 HOT 1
- 问下如何正确地hook系统函数?
- support linux io_uring HOT 1
- unify thread and coroutine io handling
- split io read and write event HOT 1
- How does it actually work
- linux: file descriptor leak in epoll code HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from may.