tcontract_exec/lib.rs
1//! CPU resources for the tcontract stack: scratch memory and contraction policy.
2//!
3//! Placement (where tasks run, and how many at once) belongs to
4//! [`threadteam`]: a host owns a [`threadteam::Pool`], lends it through
5//! [`Pool`], and each operation takes an [`Exec`], a bundle of one
6//! [`threadteam::Exec`] token, an optional workspace and a [`BatchPolicy`].
7//! This crate starts no task and exposes no scheduler type. See
8//! `PERFORMANCE_TIPS.md`, CPU Threading Contract.
9//!
10//! # Examples
11//!
12//! ```
13//! use tcontract_exec::{Exec, Pool};
14//! let sp = threadteam::Pool::builder().threads(2).build().unwrap();
15//! let pool = Pool::borrow(&sp);
16//! let mut exec = Exec::new(&pool, 2).unwrap();
17//! assert_eq!(exec.budget(), pool.size().min(2));
18//! let total = std::sync::atomic::AtomicUsize::new(0);
19//! exec.token().for_ranges(100, 1.try_into().unwrap(), |r| {
20//! total.fetch_add(r.len(), std::sync::atomic::Ordering::Relaxed);
21//! });
22//! assert_eq!(total.into_inner(), 100);
23//! ```
24pub mod batch;
25mod error;
26mod exec;
27pub mod host;
28mod pool;
29mod workspace;
30
31pub use batch::{BatchDecision, BatchPolicy, BatchQuery, BatchStrategy, WorkModel};
32pub use error::ExecError;
33pub use exec::Exec;
34pub use host::HostClass;
35pub use pool::Pool;
36pub use workspace::{
37 ArenaProvider, TeamLease, Workspace, WorkspaceProvider, WorkspaceReq, WorkspaceStats,
38};