[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M698X96GK5JA8C75N9A6AJXR":3,"skill-same:01M698X96GK5JA8C75N9A6AJXR":77},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":17,"sourceHtmlUrl":18,"categories":19,"keywords":30,"publishedAt":48,"linkOnly":49,"markdownContent":50,"markdownBody":51,"frontMatter":52,"refName":53,"commitSha":54,"skillDirectory":55,"forksCount":56,"repositoryHtmlUrl":57,"repositoryHomepageUrl":58,"ownerHtmlUrl":59,"ownerBlogUrl":60,"ownerDescription":61,"updatedAt":62,"install":63,"resources":76},"01M698X96GK5JA8C75N9A6AJXR","cpp-static-thread-safety","C++ 静态线程安全标注","Enforce C++ static thread safety annotations and correct synchronization primitives. Use this skill when designing multi-threaded classes or editing guarded member fields.","强制执行 C++ 静态线程安全标注，并正确使用同步原语。当设计多线程类或修改受保护（guarded）的成员字段时，使用此技能。","google\u002Ffilament","google","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F1342004?v=4","01M698VYEFDM0VJBZDYYJ2T83S","Google","01M698W8SGYAMBEGYBK16J57R1",20747,"Apache-2.0",null,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffilament\u002Fblob\u002Fmain\u002Fskills\u002Fcpp_static_thread_safety\u002FSKILL.md",[20,25],{"categoryNo":21,"categoryName":22,"taxonomyType":23,"taxonomyTypeDesc":24},"01M8BQ6TKQDF2K4KQS863Q79P4","开发参考","SCENARIO","使用场景",{"categoryNo":26,"categoryName":27,"taxonomyType":28,"taxonomyTypeDesc":29},"01M8BQ6TQZN6R52WBJ9H8NRMQM","软件开发工程师","PROFESSION","适用职业",[31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47],"cpp","Safety","cpp static thread safety","static","thread","when","fields","synchronization primitives","multi","c++","enforce","use","primitives","editing","annotations","synchronization","correct","2026-11-10 10:12:30",false,"---\nname: cpp-static-thread-safety\ndescription: >\n  Enforce C++ static thread safety annotations and correct synchronization primitives.\n  Use this skill when designing multi-threaded classes or editing guarded member fields.\n---\n\n# C++ Static Thread Safety & Synchronization Guidelines\n\nFilament 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.\n\n---\n\n## 1. Selecting the Correct Lock Primitive\n\n*   **Filament Primitives (`utils::Mutex` & `utils::Condition`) — MANDATORY**:\n    *   *Rule*: All engine, backend, and utility code under `filament\u002F` must use `utils::Mutex` and `utils::Condition` exclusively. Do **not** use `std::mutex` or `std::condition_variable`.\n    *   *Deadlock & Order Debugging*: `utils::Mutex` transparently integrates with Filament's compile-time lock debugging facility (`FILAMENT_DEBUG_MUTEX` \u002F `-u`). When enabled, it maintains a global cycle dependency graph via BFS during `lock()` and `try_lock()`, immediately trapping lock-order inversions and self-deadlocks with exact `CallStack` traces. Any locks defined via `std::mutex` bypass this tracker entirely and remain invisible to deadlock diagnostics.\n    *   *Memory & Cache Hygiene*: On Android and Linux (`linuxutil::Mutex`), `utils::Mutex` is only 4 bytes (a single atomic futex word) versus 40 bytes for `std::mutex`. For structures allocated in large volumes or embedded in handles\u002Ffences, this 10x size reduction prevents struct bloat and maintains cache-line density.\n    *   *Condition Variable Support*: `utils::Condition` (`Condition::wait` \u002F `wait_until`) is explicitly templated (`template \u003Ctypename M>`) to work seamlessly with `UniqueLock\u003Cutils::Mutex>` for producer-consumer queues and blocking wait loops.\n    *   *Priority Inversion Reality*: C++ standard `std::mutex` (`pthread_mutex_t`) does **not** provide priority inheritance out of the box (`PTHREAD_PRIO_NONE`). Therefore, `std::mutex` offers zero priority inversion protection over `utils::Mutex`.\n\n---\n\n## 2. Lock Guard & RAII Lifetime Conventions\n\n*   **Immutability Invariant**: Use `LockGuard const` as the default for all standard synchronized blocks to guarantee scope-bound read-only lock scopes.\n    ```cpp\n    \u002F\u002F Correct\n    utils::LockGuard const lock(mLock);\n    ```\n*   **Condition Variables Overloads**: Use `UniqueLock` (non-const) strictly when passing locks to condition variables (`wait(lock)`) or when explicit `.unlock()` \u002F `.lock()` boundaries are required for performance or deadlock prevention.\n*   **Lock Dependency**: Any source file (`.cpp`) that instantiates `LockGuard` or `UniqueLock` **must** explicitly include the matching utility header:\n    ```cpp\n    #include \u003Cutils\u002FMutex.h>\n    ```\n\n---\n\n## 3. Resolving Clang's Lambda Closure Limitations\n\nClang 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.\n\nTo resolve this, use one of the following approved patterns:\n\n### Pattern A: Inner Lambda Bypass (Recommended)\nDecorate *only* the CV wait predicate lambda operator with `UTILS_NO_THREAD_SAFETY_ANALYSIS` to ignore nested boundaries while preserving outer compile-time checks:\n```cpp\nUniqueLock lock(mQueueLock);\nmQueueCondition.wait(lock, [this]() UTILS_NO_THREAD_SAFETY_ANALYSIS {\n    return mExitRequested || \n           (!std::ranges::all_of(mQueues, [](auto&& q) { return q.empty(); }));\n});\n```\n\n### Pattern B: Manual Loop Inlining\nIf 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:\n```cpp\nUniqueLock lock(mLock);\nwhile (mFreeSpace \u003C requiredSize) {\n    mCondition.wait(lock);\n}\n```\n\n---\n\n## 4. Dynamic Threading & Preprocessor Safety\n\n*   **Single-Threaded Parity**: All thread safety annotations (`UTILS_GUARDED_BY`) are conditionally compiled out on single-threaded configurations. To prevent compile crashes when `FILAMENT_SINGLE_THREADED` is defined, standard annotations are gated by `UTILS_HAS_THREADING` in `compiler.h`.\n","# C++ Static Thread Safety & Synchronization Guidelines\n\nFilament 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.\n\n---\n\n## 1. Selecting the Correct Lock Primitive\n\n*   **Filament Primitives (`utils::Mutex` & `utils::Condition`) — MANDATORY**:\n    *   *Rule*: All engine, backend, and utility code under `filament\u002F` must use `utils::Mutex` and `utils::Condition` exclusively. Do **not** use `std::mutex` or `std::condition_variable`.\n    *   *Deadlock & Order Debugging*: `utils::Mutex` transparently integrates with Filament's compile-time lock debugging facility (`FILAMENT_DEBUG_MUTEX` \u002F `-u`). When enabled, it maintains a global cycle dependency graph via BFS during `lock()` and `try_lock()`, immediately trapping lock-order inversions and self-deadlocks with exact `CallStack` traces. Any locks defined via `std::mutex` bypass this tracker entirely and remain invisible to deadlock diagnostics.\n    *   *Memory & Cache Hygiene*: On Android and Linux (`linuxutil::Mutex`), `utils::Mutex` is only 4 bytes (a single atomic futex word) versus 40 bytes for `std::mutex`. For structures allocated in large volumes or embedded in handles\u002Ffences, this 10x size reduction prevents struct bloat and maintains cache-line density.\n    *   *Condition Variable Support*: `utils::Condition` (`Condition::wait` \u002F `wait_until`) is explicitly templated (`template \u003Ctypename M>`) to work seamlessly with `UniqueLock\u003Cutils::Mutex>` for producer-consumer queues and blocking wait loops.\n    *   *Priority Inversion Reality*: C++ standard `std::mutex` (`pthread_mutex_t`) does **not** provide priority inheritance out of the box (`PTHREAD_PRIO_NONE`). Therefore, `std::mutex` offers zero priority inversion protection over `utils::Mutex`.\n\n---\n\n## 2. Lock Guard & RAII Lifetime Conventions\n\n*   **Immutability Invariant**: Use `LockGuard const` as the default for all standard synchronized blocks to guarantee scope-bound read-only lock scopes.\n    ```cpp\n    \u002F\u002F Correct\n    utils::LockGuard const lock(mLock);\n    ```\n*   **Condition Variables Overloads**: Use `UniqueLock` (non-const) strictly when passing locks to condition variables (`wait(lock)`) or when explicit `.unlock()` \u002F `.lock()` boundaries are required for performance or deadlock prevention.\n*   **Lock Dependency**: Any source file (`.cpp`) that instantiates `LockGuard` or `UniqueLock` **must** explicitly include the matching utility header:\n    ```cpp\n    #include \u003Cutils\u002FMutex.h>\n    ```\n\n---\n\n## 3. Resolving Clang's Lambda Closure Limitations\n\nClang 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.\n\nTo resolve this, use one of the following approved patterns:\n\n### Pattern A: Inner Lambda Bypass (Recommended)\nDecorate *only* the CV wait predicate lambda operator with `UTILS_NO_THREAD_SAFETY_ANALYSIS` to ignore nested boundaries while preserving outer compile-time checks:\n```cpp\nUniqueLock lock(mQueueLock);\nmQueueCondition.wait(lock, [this]() UTILS_NO_THREAD_SAFETY_ANALYSIS {\n    return mExitRequested || \n           (!std::ranges::all_of(mQueues, [](auto&& q) { return q.empty(); }));\n});\n```\n\n### Pattern B: Manual Loop Inlining\nIf 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:\n```cpp\nUniqueLock lock(mLock);\nwhile (mFreeSpace \u003C requiredSize) {\n    mCondition.wait(lock);\n}\n```\n\n---\n\n## 4. Dynamic Threading & Preprocessor Safety\n\n*   **Single-Threaded Parity**: All thread safety annotations (`UTILS_GUARDED_BY`) are conditionally compiled out on single-threaded configurations. To prevent compile crashes when `FILAMENT_SINGLE_THREADED` is defined, standard annotations are gated by `UTILS_HAS_THREADING` in `compiler.h`.\n",{"name":5,"description":7},"main","fd9ec7ff9510df148011c5326bcb50d4bfb811ca","skills\u002Fcpp_static_thread_safety",2305,"https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffilament","https:\u002F\u002Fgoogle.github.io\u002Ffilament\u002F","https:\u002F\u002Fgithub.com\u002Fgoogle","https:\u002F\u002Fopensource.google\u002F","Google ❤️ Open Source","2026-11-14 13:54:43",{"source":9,"skillName":5,"commands":64,"prompt":74,"zipAvailable":75},[65,68,71],{"tool":66,"command":67},"npx","npx skills add google\u002Ffilament --skill cpp-static-thread-safety",{"tool":69,"command":70},"bunx","bunx skills add google\u002Ffilament --skill cpp-static-thread-safety",{"tool":72,"command":73},"pnpm","pnpm dlx skills add google\u002Ffilament --skill cpp-static-thread-safety","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffilament\u002Fblob\u002Fmain\u002Fskills\u002Fcpp_static_thread_safety\u002FSKILL.md",true,[],[78,101,120,142,167,187],{"skillNo":79,"name":80,"nameZh":81,"description":82,"descriptionZh":83,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":17,"sourceHtmlUrl":84,"categories":85,"keywords":90,"publishedAt":48},"01M698XTTZP1MWPYW9EVV7DF2Q","filament-math","Filament 数学运算与坐标变换","Enforce correct mathematical primitives and naming conventions in Filament code. Use this skill when performing coordinate transformations, vector math, or projection setups.","确保 Filament 代码中数学原语和命名约定的正确性。在执行坐标变换、向量运算或投影设置时使用此技能。","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffilament\u002Fblob\u002Fmain\u002Ftools\u002Fai\u002Fagents\u002Fskills\u002Ffilament_math\u002FSKILL.md",[86,87],{"categoryNo":26,"categoryName":27,"taxonomyType":28,"taxonomyTypeDesc":29},{"categoryNo":88,"categoryName":89,"taxonomyType":23,"taxonomyTypeDesc":24},"01M8BRSRXQPYT60FQ3976GDV4Q","C++ 开发",[91,92,36,93,94,47,43,42,95,41,96,97,98,99,100],"filament math","math","code","vector","coordinate","conventions","Mathematical","naming","naming conventions","performing",{"skillNo":102,"name":103,"nameZh":104,"description":105,"descriptionZh":106,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":17,"sourceHtmlUrl":107,"categories":108,"keywords":111,"publishedAt":48},"01M698XRXR5Q463GQ03RDBD9FR","filament-lifetime","Filament 对象生命周期管理","Enforce correct Filament object creation and destruction lifecycles. Use this skill when initializing rendering pipelines or allocating\u002Fdeallocating GPU buffers and entities.","确保 Filament 对象创建与销毁生命周期的正确性。在初始化渲染管线或分配\u002F释放 GPU 缓冲区和实体（entity）时使用此技能。","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffilament\u002Fblob\u002Fmain\u002Ftools\u002Fai\u002Fagents\u002Fskills\u002Ffilament_lifetime\u002FSKILL.md",[109,110],{"categoryNo":26,"categoryName":27,"taxonomyType":28,"taxonomyTypeDesc":29},{"categoryNo":88,"categoryName":89,"taxonomyType":23,"taxonomyTypeDesc":24},[112,42,113,114,41,115,47,116,117,118,36,119],"filament lifetime","rendering","creation","pipelines","gpu","destruction","object","entities",{"skillNo":121,"name":122,"nameZh":123,"description":124,"descriptionZh":125,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":17,"sourceHtmlUrl":126,"categories":127,"keywords":132,"publishedAt":48},"01M698XQ0E9RE6RDFYKS2PF1S1","cherry-pick","Git 提交 cherry-pick 与回填","Cherry-pick a commit onto another branch and open the PR. Use when the user asks to cherry-pick or backport a commit or PR to a release branch.","将某个提交 cherry-pick 到另一个分支并创建 PR。当用户要求将某个提交或 PR cherry-pick 或回填（backport）到发布分支时使用。","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffilament\u002Fblob\u002Fmain\u002Fthird_party\u002Fdawn\u002Fthird_party\u002Fdirectx-shader-compiler\u002Fsrc\u002F.github\u002Fskills\u002Fcherry-pick\u002FSKILL.md",[128,129],{"categoryNo":26,"categoryName":27,"taxonomyType":28,"taxonomyTypeDesc":29},{"categoryNo":130,"categoryName":131,"taxonomyType":23,"taxonomyTypeDesc":24},"01M8BR5V701HCN066VEP7H4812","代码仓库协作管理",[133,134,135,136,36,137,42,138,139,140,141],"pick","cherry pick","branch","open","user","backport","commit","pr","release",{"skillNo":143,"name":144,"nameZh":145,"description":146,"descriptionZh":147,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":17,"sourceHtmlUrl":148,"categories":149,"keywords":152,"publishedAt":48},"01M698XN2P44Y956SJRD7CPB22","verification-protocols","C++ 代码验证流程","Standard verification pipeline to execute after modifying C++ source or header files. Use this skill to format includes, build the engine, and run core tests.","修改 C++ 源文件或头文件后需执行的标准验证流程。使用此技能格式化 include 语句、构建引擎并运行核心测试。","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffilament\u002Fblob\u002Fmain\u002Fskills\u002Fverification_protocols\u002FSKILL.md",[150,151],{"categoryNo":26,"categoryName":27,"taxonomyType":28,"taxonomyTypeDesc":29},{"categoryNo":88,"categoryName":89,"taxonomyType":23,"taxonomyTypeDesc":24},[153,154,155,156,157,158,159,160,161,42,162,163,40,164,165,166],"protocols","verification","verification protocols","core","run","pipeline","format","engine","execute","files","build","tests","source","standard",{"skillNo":168,"name":169,"nameZh":170,"description":171,"descriptionZh":172,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":17,"sourceHtmlUrl":173,"categories":174,"keywords":177,"publishedAt":48},"01M698XK6J428QZM1WGVWW50JE","preprocessor-guard-hygiene","C++ 预处理保护规范检查","Enforce preprocessor guard rules and macro-dependent inclusion hygiene in C++. Use this skill when modifying conditional imports or preprocessor directives.","在 C++ 中强制实施预处理保护（preprocessor guard）规则以及依赖宏的包含卫生规范。在修改条件导入或预处理指令时使用此技能。","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffilament\u002Fblob\u002Fmain\u002Fskills\u002Fpreprocessor_guard_hygiene\u002FSKILL.md",[175,176],{"categoryNo":26,"categoryName":27,"taxonomyType":28,"taxonomyTypeDesc":29},{"categoryNo":88,"categoryName":89,"taxonomyType":23,"taxonomyTypeDesc":24},[178,179,180,181,36,182,183,184,185,40,41,42,186],"hygiene","guard","preprocessor guard hygiene","Rules","directives","conditional","imports","inclusion","macro",{"skillNo":188,"name":189,"nameZh":190,"description":191,"descriptionZh":192,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":17,"sourceHtmlUrl":193,"categories":194,"keywords":197,"publishedAt":48},"01M698XHA1J01F915DKYHXZ18C","header-self-containment","C++ 头文件自包含检查","Enforce strict header self-containment so that every header file compiles independently. Use this skill when creating or modifying C++ header files.","强制实施严格的头文件自包含规范，确保每个头文件都能独立编译。在创建或修改 C++ 头文件时使用此技能。","https:\u002F\u002Fgithub.com\u002Fgoogle\u002Ffilament\u002Fblob\u002Fmain\u002Fskills\u002Fheader_self_containment\u002FSKILL.md",[195,196],{"categoryNo":26,"categoryName":27,"taxonomyType":28,"taxonomyTypeDesc":29},{"categoryNo":88,"categoryName":89,"taxonomyType":23,"taxonomyTypeDesc":24},[198,199,200,36,40,41,162,42,201],"header self containment","containment","self","file"]