New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LocalSend instead of Send #66
Conversation
Second commit makes possible the following: extern crate coroutine;
use std::rc::Rc;
use std::cell::RefCell;
use coroutine::asymmetric::Coroutine;
fn main() {
let rc = Rc::new(RefCell::new(0));
let rc1 = rc.clone();
let mut coro1 = Coroutine::spawn(move |me| {
*rc1.borrow_mut() = 1;
let val = *rc1.borrow();
me.yield_with(val); // (*rc1.borrow()) - fails with already borrowed
});
let rc2 = rc.clone();
let mut coro2 = Coroutine::spawn(move |me| {
*rc2.borrow_mut() = 2;
let val = *rc2.borrow();
me.yield_with(val);
});
println!("First: {}", (*coro1).yield_with(0));
println!("Second: {}", (*coro2).yield_with(0));
} |
@zonyitoo Is there any reason we have to leave |
Well, it is still unsafe because you just tried to bypass the check. I cannot remember why I added |
If you are interested in building a library that would migrate coroutines between threads (which is the only reason why you care about TLS safety), why not join us to improve coio-rs. |
@zonyitoo No, I won't use library with threads. I'm moving simulation Lua's library to Rust and want to use coroutines inside one thread only. But to use reference counters without overhead ( I've add TLS example to show:
I'll squash the commits, remove tls example, and Let's check compatibility with other libs using this. If nothing breaks why we have to still using What libraries I need to backward compatibility check with this PR? |
Build successful! I've also checked it with my simulator. It works well without |
None, I really don't know who is using this library. This library was built as a base library for coio-rs and mioco, and all of us use our own encapsulation upon context-rs now. I will merge this PR, and lets see who will complain about it. |
@zonyitoo Thank you! |
Proposal to fix #31
With this PR I can compile
simple
example, but can't compiletls
example:Fails with: