google/filament/cpp-static-thread-safety
Claude Code and agent skill by google/filament
- vendor
Checking that the SKILL.md file is still in the repository.
Enforce C++ static thread safety annotations and correct synchronization primitives. Use this skill when designing multi-threaded classes or editing guarded member fields.
Install
npx vskill@latest install google/filament/cpp-static-thread-safetySKILL.md
The same SKILL.md was published earlier as google/filament/cpp-static-thread-safety.
C++ Static Thread Safety & Synchronization Guidelines
Filament leverages Clang's static thread safety analysis to verify lock holding requirements at compile-time. All multi-threaded classes must use explicit capability annotations to guarantee race-free state access.
1. Selecting the Correct Lock Primitive
- Filament Primitives (`utils::Mutex` & `utils::Condition`) — MANDATORY:
- Rule: All engine, backend, and utility code under
filament/must useutils::Mutexandutils::Conditionexclusively. Do not usestd::mutexorstd::condition_variable. - Deadlock & Order Debugging:
utils::Mutextransparently integrates with Filament's compile-time lock debugging facility (FILAMENT_DEBUG_MUTEX/-u). When enabled, it maintains a global cycle dependency graph via BFS duringlock()andtry_lock(), immediately trapping lock-order inversions and self-deadlocks with exactCallStacktraces. Any locks defined viastd::mutexbypass this tracker entirely and remain invisible to deadlock diagnostics. - Memory & Cache Hygiene: On Android and Linux (
linuxutil::Mutex),utils::Mutexis only 4 bytes (a single atomic futex word) versus 40 bytes forstd::mutex. For structures allocated in large volumes or embedded in handles/fences, this 10x size reduction prevents struct bloat and maintains cache-line density. - Condition Variable Support:
utils::Condition(Condition::wait/wait_until) is explicitly templated (template <typename M>) to work seamlessly withUniqueLock<utils::Mutex>for producer-consumer queues and blocking wait loops. - Priority Inversion Reality: C++ standard
std::mutex(pthread_mutex_t) does not provide priority inheritance out of the box (PTHREAD_PRIO_NONE). Therefore,std::mutexoffers zero priority inversion protection overutils::Mutex.
2. Lock Guard & RAII Lifetime Conventions
- Immutability Invariant: Use
LockGuard constas the default for all standard synchronized blocks to guarantee scope-bound read-only lock scopes.
``cpp // Correct utils::LockGuard const lock(mLock); ``
- Condition Variables Overloads: Use
UniqueLock(non-const) strictly when passing locks to condition variables (wait(lock)) or when explicit.unlock()/.lock()boundaries are required for performance or deadlock prevention. - Lock Dependency: Any source file (
.cpp) that instantiatesLockGuardorUniqueLockmust explicitly include the matching utility header:
``cpp #include <utils/Mutex.h> ``
3. Resolving Clang's Lambda Closure Limitations
Clang evaluates C++ anonymous closures (lambdas) as separate context boundaries. Because lambdas lack capability attributes, standard condition variable waits passing local predicates (e.g., using std::ranges::all_of) will trigger false-positive thread safety errors.
To resolve this, use one of the following approved patterns:
Pattern A: Inner Lambda Bypass (Recommended)
Decorate only the CV wait predicate lambda operator with UTILS_NO_THREAD_SAFETY_ANALYSIS to ignore nested boundaries while preserving outer compile-time checks:
Pattern B: Manual Loop Inlining
If the check is flat, completely inline the CV predicate as a standard while loop to bring the member variables directly into the parent function's locked scope:
4. Dynamic Threading & Preprocessor Safety
- Single-Threaded Parity: All thread safety annotations (
UTILS_GUARDED_BY) are conditionally compiled out on single-threaded configurations. To prevent compile crashes whenFILAMENT_SINGLE_THREADEDis defined, standard annotations are gated byUTILS_HAS_THREADINGincompiler.h.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files. Certified 25 Oct 2026.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/cpp_static_thread_safety/SKILL.md
Popularity
- Repository stars
- 20,548
- Repository forks
- 2,270
- 7-day trend score
- 50
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/google/filament/cpp-static-thread-safety)