cheatah
Guide

Concurrency

Member cheatah::io::input (std::string_view prompt="")

blocks the calling thread until a full line (or EOF) arrives on stdin.

Member cheatah::io::print (const Args &... args)

writes to the shared std::cout; concurrent prints from several threads do not race but may interleave their characters.

Member cheatah::io::rprint (const Args &... args)

writes to the shared std::cout; concurrent prints from several threads do not race but may interleave their characters.

Member cheatah::linalg::matmul (const Array< T > &a, const Array< T > &b)

deliberately single-threaded (the fastest-per-core contract); parallelize across independent products in the caller.

Member cheatah::memory::Lease< T, M >::Lease (T *obj, std::shared_ptr< detail::Gate > gate, std::function< void()> release) noexcept

called by the owner with its coordinator mutex held — never construct one yourself.

Member cheatah::memory::Lease< T, M >::on_interrupt (std::function< void()> handler)

the handler never fires asynchronously — only from inside a valid() call, on the thread that polls it.

Member cheatah::memory::Lease< T, M >::read () const

race-free while the lease is held: a writer cannot proceed until this lease releases (yielding on !valid() is cooperative, not forced). No lock is taken here.

Member cheatah::memory::Lease< T, M >::valid () const noexcept

an atomic acquire load; the first observation of a stop acks and wakes the owner (that one call briefly takes the owner's mutex) — polling this from the holding thread is what lets a drain/preempt make progress. The lease handle itself is not internally synchronized: poll from the thread that holds the lease.

Member cheatah::memory::Lease< T, M >::write (T value)

exclusive: no reader or other writer coexists while this lease is valid. A writer that observed !valid() (an immediate-write preempted it) must wait for valid() to flip back before writing again — writing while suspended races with the immediate-write.

Member cheatah::memory::Lease< T, M >::~Lease ()

the release callback takes the owner's coordinator mutex and wakes waiting requests (a draining writer proceeds once the last reader releases here).

Member cheatah::memory::Owner< T >::Owner (T &&value, policy pol=policy::interleave)

construct before sharing; the pinned Owner must outlive every lease and every thread that uses it.

Member cheatah::memory::Owner< T >::rread ()

callable from any thread; readers share. Writer-preference: this waits while any write is active, suspended, or queued, so writers cannot starve.

Member cheatah::memory::Owner< T >::rwrite ()

callable from any thread. Drain-before-write: flips the current read generation's gate and waits until every reader has released and no other write is active; an immediate-write skips the queue and additionally preempts a cooperating active writer (which resumes after).

Member cheatah::memory::Request< LeaseT >::acquire (std::function< void()> on_interrupt={})

one-shot: a second acquire() on the same request throws std::future_error. on_interrupt later fires on whichever thread polls the lease's valid() — never asynchronously.

Member cheatah::random::choice (const R &seq)

thread-safe — draws its index from the per-thread engine via randint.

Member cheatah::random::gauss (double mu, double sigma)

thread-safe — draws from the per-thread (thread_local) engine, so concurrent draws never race.

Member cheatah::random::randint (long long a, long long b)

thread-safe — draws from the per-thread (thread_local) engine, so concurrent draws never race.

Member cheatah::random::random ()

thread-safe — draws from the per-thread (thread_local) engine, so concurrent draws never race.

Member cheatah::random::seed (unsigned long long s)

seeds the calling thread's engine only; other threads' streams are unaffected.

Member cheatah::random::uniform (double a, double b)

thread-safe — draws from the per-thread (thread_local) engine, so concurrent draws never race.

Member cheatah::requests::request (builtins::Value auto &&method, builtins::Value auto &&url, builtins::Value auto &&o)

blocking, with every hop's socket I/O bounded by timeout_ms; no shared state — concurrent requests from separate threads are independent.

Member cheatah::socket::accept (long long fd)

blocks the calling thread until a client connects.

Member cheatah::socket::Conn::recv (long long bufsize)

blocks until data, EOF, or the set_timeout() deadline.

Member cheatah::socket::connect (long long fd, const std::string &host, long long port)

blocks until the TCP handshake completes or fails.

Member cheatah::socket::Listener::accept ()

blocks the calling thread until a client connects.

Member cheatah::socket::open (const std::string &host, long long port)

blocks until the TCP handshake completes or fails.

Member cheatah::socket::recv (long long fd, long long bufsize)

blocks until data, EOF, or the set_timeout() deadline; a shutdown() from another thread wakes it with EOF.

Member cheatah::socket::sendall (long long fd, const std::string &data)

may block while the peer's receive window is full; bounded per send by the set_timeout() send deadline.

Member cheatah::socket::shutdown (long long fd)

safe to call from another thread while a recv() on fd blocks — waking that reader is exactly what it is for.

Member cheatah::socket::tcp_connect (const std::string &host, long long port)

blocks until the TCP handshake completes or fails.

Member cheatah::thread::spawn (F f, Args &&... args)

the worker may already be running before spawn returns. Copyable arguments are captured before the thread starts, so the caller may immediately mutate or destroy its originals; a by-reference argument (a pinned memory.Owner) is shared with the running worker from that moment on.

Class cheatah::thread::Thread

the handle itself is not internally synchronized — drive a given Thread from one thread at a time (the worker it owns is, of course, another thread; join() is the synchronization point with it).

Member cheatah::thread::Thread::join ()

blocks the calling thread; the worker's writes happen-before join() returns (the join is the synchronization). One-shot — a second join raises.

Member cheatah::thread::Thread::operator= (Thread &&other) noexcept

may block: the destination joins its old worker before adopting the new one.

Member cheatah::thread::Thread::Thread (std::thread t, std::shared_ptr< detail::State > state) noexcept

the worker is already running when the handle adopts it.

Member cheatah::thread::Thread::~Thread ()

blocks the destroying thread until the worker finishes — on every exit path, including unwinding.

Member cheatah::time::sleep (double seconds)

blocks only the calling thread; other threads keep running.

Member cheatah::tls::accept (long long fd, const std::string &cert_pem, const std::string &key_pem)

blocks awaiting the client's handshake flights — bound it with socket.set_timeout() on fd so a silent client cannot hang the server.

Member cheatah::tls::Conn::recv (long long bufsize)

blocks (bounded by the fd's socket.set_timeout()) only while nothing is ready; a session has ONE reader — shutdown() is the cross-thread wake-up.

Member cheatah::tls::Conn::send (const std::string &data)

a session is single-owner — never send on one session from two threads at once (the record sequence would race). Separate sessions are independent.

Member cheatah::tls::Conn::shutdown ()

safe to call from another thread while the owner's recv() blocks — that wake-up is its purpose; then join the reader before close().

Member cheatah::tls::last_error ()

the error slot is thread-local — read it on the thread whose call failed.

Member cheatah::tls::open (long long fd, const std::string &server_name, bool insecure=false, const std::string &ca_file="")

blocks for the handshake round trip — bound it with socket.set_timeout() on fd.

Member cheatah::websocket::Client::recv ()

blocks until a full message arrives; a session has ONE reader — shutdown() is the cross-thread wake-up.

Member cheatah::websocket::Client::shutdown ()

safe to call from another thread while the owner's recv() blocks — that wake-up is its purpose; then join the reader before close().

Member cheatah::websocket::open (const std::string &host, long long port, const std::string &path, const std::string &server_name, bool insecure=false, const std::string &ca_file="", bool secure=true)

blocks for the TCP/TLS/upgrade round trips.

Member cheatah::websocket::open_url (const std::string &url, bool insecure=false, const std::string &ca_file="")

blocks for the TCP/TLS/upgrade round trips.

File routines.hpp

every routine is DELIBERATELY single-threaded (no hidden thread pool — the fastest-per-core contract); the caller composes parallelism across independent problems.