Skip to main content

Module multi_thread

Module multi_thread 

Source
Expand description

§多线程运行时

§Examples

use pi_async_rt::rt::{AsyncRuntime, AsyncRuntimeExt};
use pi_async_rt::rt::multi_thread::{MultiTaskRuntime, MultiTaskRuntimeBuilder, StealableTaskPool};

let pool = StealableTaskPool::with(4,100000,[1, 254],3000);
let builer = MultiTaskRuntimeBuilder::new(pool)
    .set_timer_interval(1)
    .init_worker_size(4)
    .set_worker_limit(4, 4);
let rt = builer.build();
let _ = rt.spawn(async move {});

§Concurrency and worker ownership

The runtime shares one task pool between all worker threads. Pool-wide state must therefore use thread-safe containers, while each worker-local stack, queue selector, and deque worker may only be accessed by the OS thread bound to that exact pool and worker slot. The implementation binds a private {thread_id, pool pointer} context when a worker starts and validates it before every owner-only access. A wrong-pool owner operation panics before touching worker-local state; cross-runtime spawn_local remains a supported public-queue fallback.

This validation is O(1), performs one thread-local read and pointer comparison, does not allocate, clone, lock, spin, block, poll user code, or call into V8/FFI. See the standard regression target tests/stealable_task_pool_concurrency.rs.

Structs§

ComputationalTaskPool
计算型多线程任务池,适合 CPU 密集型应用,不支持运行时伸缩。
MultiTaskRuntime
异步多线程任务运行时,支持运行时线程伸缩
MultiTaskRuntimeBuilder
异步多线程任务运行时构建器
StealableTaskPool
可窃取的混合多线程任务池。