Comments (4)
schedule
is called when the Waker
is waked. It is only not Send + Sync
for spawn_unchecked
, which is unsafe and stipulates that the Waker
not be waked on other threads.
from async-task.
Please point out if I'm wrong. I wrote a program like this:
use async_task::Runnable;
use send_wrapper::SendWrapper;
use std::{cell::RefCell, collections::VecDeque, future::poll_fn, rc::Rc, task::Poll};
fn main() {
let runnables = Rc::new(RefCell::new(VecDeque::<Runnable>::new()));
let schedule = {
let runnables = SendWrapper::new(runnables.clone());
move |r| runnables.borrow_mut().push_back(r)
};
let (runnable, task) = async_task::spawn_local(
poll_fn(|cx| {
cx.waker().wake_by_ref();
Poll::<()>::Pending
}),
schedule,
);
let t = std::thread::spawn(move || smol::block_on(task));
runnable.schedule();
loop {
let next_task = runnables.borrow_mut().pop_front();
if let Some(r) = next_task {
r.run();
} else {
break;
}
}
t.join().unwrap();
}
It spawns a async block and waits the task in another thread. The schedule
will panic if it's called in other threads. However, this program just blocks and never panics nor exits. Why?
from async-task.
The waker from the task on the main thread isn't being sent to the spawned thread. The waker from the block_on
on the spawned thread is being sent to the main thread. The reason why the thread stops is because it's waiting on task
forever. The loop breaks out before the task can be scheduled again.
from async-task.
Thank you! Now the problem is solved.
from async-task.
Related Issues (20)
- Can there be no additional scheduling of tasks when Task cancel or Detach HOT 1
- Custom allocators HOT 3
- How can I clone a `Task` HOT 6
- Add names to tasks HOT 1
- Dummy task HOT 2
- Bug: Unit test with expected panic message randomly fails because of crate-specific panic message HOT 2
- Why was metadata removed from a previous version of async-task? HOT 2
- Run tests for async-executor in CI
- Http clients for async-task HOT 5
- Efficiently support bounded queues for scheduling? HOT 5
- Why manual call of schedule is needed on runnable? HOT 2
- fails to test examples without feature std HOT 1
- Use portable-atomic HOT 3
- Unclear behaviour of casting ptr of RawTask to ptr of Header HOT 1
- Implicit boxing of large futures causes excessive monomorphization HOT 2
- Clarify safety of spawn_unchecked for Runnable lifetime HOT 2
- `Builder::spawn` should encode the metadata lifetime contract HOT 3
- overgeneral documentation HOT 4
- Duplicated raw function monomorphizations
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 async-task.