diff --git a/AGENTS.md b/AGENTS.md index 1cf3451198..35f4c7177f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -231,7 +231,10 @@ Two more rules that catch most of the rest: - **Read mutable shared state once per operation.** Re-reading the same field for several decisions in one pass lets it change mid-pass, so the results disagree with each other. -Prefer `AutoClosableReentrantLock` over `synchronized`, matching the rest of the codebase. +**Which lock to use depends on the module.** In JVM and shared modules, including `sentry` core, +use `AutoClosableReentrantLock`: `synchronized` pins virtual threads on JDK 21–23. In Android-only +modules (`sentry-android-*`), use `synchronized`, since Android has no virtual threads. Don't rewrite +existing locks only to switch between the two. ### Measuring Time diff --git a/REVIEWS.md b/REVIEWS.md index 3732a5785a..4fc27faebd 100644 --- a/REVIEWS.md +++ b/REVIEWS.md @@ -105,7 +105,9 @@ rule file in [`.cursor/rules/`](.cursor/rules) for the area the diff touches (`a plain field read is a data race, not merely a stale value. - Read mutable shared state once per operation. Re-reading the same field for several decisions in one pass lets it change mid-pass, so the results disagree with each other. -- Prefer the `synchronized` keyword. Existing code that uses `AutoClosableReentrantLock` is legacy. +- In JVM and shared modules, including `sentry` core, use `AutoClosableReentrantLock`, not + `synchronized`, which pins virtual threads on JDK 21–23. In Android-only modules + (`sentry-android-*`), use `synchronized`. Don't flag existing locks that predate this rule. - New classes have a clear and defined threading and concurrency model as part of the javadoc if needed.