From e3d8fe4854a7ef7ff0637688cda9e65feb680122 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Thu, 15 Oct 2026 12:37:10 +0300 Subject: Replace the writer spin lock with a blocking mutex term_write_begin spun on an atomic sequence word. A waiter burned CPU, and with no priority inheritance a SCHED_FIFO waiter could starve a preempted holder on the same CPU. The writer section is now a pthread mutex with PTHREAD_PRIO_INHERIT where the platform has it, and an SRWLOCK on Windows. Re-entry on the owning thread still only counts the depth. The platform wrapper (init, lock, unlock, destroy) is in compat.h. term_new initializes the mutex, and term_free destroys it. Meson links the thread library into the core, term_dep, and term_internal_dep. The README, term.h, and the amalgamation note say that POSIX needs -pthread. Tests: the feed and snapshot thread test now checks the final screen and history against a serial reference. A new test checks that term_lock nests and that another thread waits for the last term_unlock. Co-Authored-By: Claude Haiku 5.5 --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index e877a01..bdd686b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ term is a headless terminal core: the parser, screen ring, logical-line history store, write core, and viewport snapshots. It is a C11 library -with no dependency but libm. +with no dependency but libm and, on POSIX, the thread library (`-pthread`). | Path | Contents | | --- | --- | @@ -23,14 +23,16 @@ Pick one of these: sets the lowest instruction set, such as `-march=x86-64-v3`. - **Amalgamation**: run `tools/amalgamate.py . OUT`. It writes `OUT/term.c` and `OUT/term.h`. Compile `term.c` with any C11 compiler - and link libm. A Rust `build.rs` needs one + and link libm and the thread library: `cc -std=c11 -pthread -c term.c` + on POSIX. A Rust `build.rs` needs one `cc::Build::new().file("term.c").compile("term")`. - **Sources**: compile `src/*.c` and `src/osc/*.c` once, with `src` and - `include/term` on the include path. + `include/term` on the include path. Link the thread library too. -The library needs nothing else. The `*-amalgamation` tests run the term -tests against the generated `term.c`, and `term-cross-test` compiles it -for aarch64, macOS, and Windows. +The library needs nothing else. On Windows the writer lock is an SRWLOCK +from the system library, so it needs no extra link. The `*-amalgamation` +tests run the term tests against the generated `term.c`, and +`term-cross-test` compiles it for aarch64, macOS, and Windows. ### SIMD level -- cgit v1.2.3