commit | a11c4b22cbcbbdbc4fa0ff62bdbffb430a9d3394 | [log] [tgz] |
---|---|---|
author | Taiki Endo <[email protected]> | Thu Jan 23 23:55:24 2025 +0900 |
committer | Taiki Endo <[email protected]> | Fri Jan 24 00:01:29 2025 +0900 |
tree | e7afc5694424c8da297a8dbe38894eb315f25ef6 | |
parent | 3421b071f1eb6200bd9c96ca4261e95c9c8ed59e [diff] |
ci: Use --errors-for-leak-kinds=definite,indirect for valgrind to work around upstream bug ``` ==5246== ==5246== HEAP SUMMARY: ==5246== in use at exit: 48 bytes in 1 blocks ==5246== total heap usage: 428 allocs, 427 frees, 51,703 bytes allocated ==5246== ==5246== Searching for pointers to 1 not-freed blocks ==5246== Checked 128,240 bytes ==5246== ==5246== 48 bytes in 1 blocks are possibly lost in loss record 1 of 1 ==5246== at 0x4E050C5: malloc (vg_replace_malloc.c:442) ==5246== by 0x22D2A7: alloc (alloc.rs:96) ==5246== by 0x22D2A7: alloc_impl (alloc.rs:192) ==5246== by 0x22D2A7: allocate (alloc.rs:254) ==5246== by 0x22D2A7: {closure#0}<std::thread::Inner> (sync.rs:484) ==5246== by 0x22D2A7: allocate_for_layout<core::mem::maybe_uninit::MaybeUninit<std::thread::Inner>, alloc::sync::{impl#14}::new_uninit::{closure_env#0}<std::thread::Inner>, fn(*mut u8) -> *mut alloc::sync::ArcInner<core::mem::maybe_uninit::MaybeUninit<std::thread::Inner>>> (sync.rs:1952) ==5246== by 0x22D2A7: new_uninit<std::thread::Inner> (sync.rs:482) ==5246== by 0x22D2A7: std::thread::Thread::new (mod.rs:1429) ==5246== by 0x22C679: std::thread::current::init_current (current.rs:227) ==5246== by 0x2361E3: current_or_unnamed (current.rs:184) ==5246== by 0x2361E3: std::sync::mpmc::context::Context::new (context.rs:72) ==5246== by 0x1BA891: __init (context.rs:43) ==5246== by 0x1BA891: call_once<fn() -> core::cell::Cell<core::option::Option<std::sync::mpmc::context::Context>>, ()> (function.rs:250) ==5246== by 0x1BA891: unwrap_or_else<core::cell::Cell<core::option::Option<std::sync::mpmc::context::Context>>, fn() -> core::cell::Cell<core::option::Option<std::sync::mpmc::context::Context>>> (option.rs:1023) ==5246== by 0x1BA891: std::sys::thread_local::native::lazy::Storage<T,D>::initialize (lazy.rs:64) ==5246== by 0x1BC045: get_or_init<core::cell::Cell<core::option::Option<std::sync::mpmc::context::Context>>, (), fn() -> core::cell::Cell<core::option::Option<std::sync::mpmc::context::Context>>> (lazy.rs:56) ==5246== by 0x1BC045: {closure#0} (mod.rs:94) ==5246== by 0x1BC045: call_once<std::sync::mpmc::context::{impl#0}::with::CONTEXT::{constant#0}::{closure_env#0}, (core::option::Option<&mut core::option::Option<core::cell::Cell<core::option::Option<std::sync::mpmc::context::Context>>>>)> (function.rs:250) ==5246== by 0x1BC045: try_with<core::cell::Cell<core::option::Option<std::sync::mpmc::context::Context>>, std::sync::mpmc::context::{impl#0}::with::{closure_env#1}<std::sync::mpmc::list::{impl#3}::recv::{closure_env#1}<test::event::CompletedTest>, ()>, ()> (local.rs:307) ==5246== by 0x1BC045: with<std::sync::mpmc::list::{impl#3}::recv::{closure_env#1}<test::event::CompletedTest>, ()> (context.rs:52) ==5246== by 0x1BC045: std::sync::mpmc::list::Channel<T>::recv (list.rs:437) ==5246== by 0x1D5336: recv<test::event::CompletedTest> (mod.rs:976) ==5246== by 0x1D5336: recv<test::event::CompletedTest> (mod.rs:850) ==5246== by 0x1D5336: run_tests<test::console::run_tests_console::{closure_env#2}> (lib.rs:391) ==5246== by 0x1D5336: test::console::run_tests_console (console.rs:322) ==5246== by 0x1F2BE6: test::test_main (lib.rs:149) ==5246== by 0x1F354A: test::test_main_static (lib.rs:171) ==5246== by 0x1B8F72: basic::main (basic.rs:0) ==5246== by 0x1AAEDA: core::ops::function::FnOnce::call_once (function.rs:250) ==5246== by 0x1A610D: std::sys::backtrace::__rust_begin_short_backtrace (backtrace.rs:152) ==5246== ==5246== LEAK SUMMARY: ==5246== definitely lost: 0 bytes in 0 blocks ==5246== indirectly lost: 0 bytes in 0 blocks ==5246== possibly lost: 48 bytes in 1 blocks ==5246== still reachable: 0 bytes in 0 blocks ==5246== suppressed: 0 bytes in 0 blocks ==5246== ==5246== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) error: test failed, to rerun pass `--test basic` ```
Task abstraction for building executors.
To spawn a future onto an executor, we first need to allocate it on the heap and keep some state attached to it. The state indicates whether the future is ready for polling, waiting to be woken up, or completed. Such a stateful future is called a task.
All executors have a queue that holds scheduled tasks:
let (sender, receiver) = flume::unbounded();
A task is created using either spawn()
, spawn_local()
, or spawn_unchecked()
which return a Runnable
and a Task
:
// A future that will be spawned. let future = async { 1 + 2 }; // A function that schedules the task when it gets woken up. let schedule = move |runnable| sender.send(runnable).unwrap(); // Construct a task. let (runnable, task) = async_task::spawn(future, schedule); // Push the task into the queue by invoking its schedule function. runnable.schedule();
The Runnable
is used to poll the task's future, and the Task
is used to await its output.
Finally, we need a loop that takes scheduled tasks from the queue and runs them:
for runnable in receiver { runnable.run(); }
Method run()
polls the task's future once. Then, the Runnable
vanishes and only reappears when its Waker
wakes the task, thus scheduling it to be run again.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.