On Thu Mar 21 10:14:29 2024 +0000, Jinoh Kang wrote:
/* Begin a reader critical section of a seqlock. * * Due to how seqlock works, a read may (transiently) fail when it races with * the writer side. On such a failure, this macro attempts to iterate multiple * times until the read succeeds. * * This leads to the following anomalies: * * - Variables ever written by the section may not have initially set values. * - Conditionally written variables may have corrupted values on section exit. * * To prevent such anomalies from causing bugs, the body should be *idempotent*. * Specifically, you should keep the following rules in mind: * * 1. Avoid if()s, loops, and other kinds of conditional execution. If they're * needed for some reason, make sure that the conditions don't depend on * values from the shared memory at all. * * 2. A variable should only ever be *either* read *or* written in a critical * section, but *not both*. An exception to this rule is when the variable * has been already written before (in the same iteration). * * 3. In general, if you want to perform computation, I/O or a blocking * operation, do so outside (before or after) the critical section. * * Any (unavoidable) violation of the rules above should be reviewed carefully * so that it maintains the property of idempotence (the section body only reads * from the latest values in the face of multiple retries.) */ #define SHARED_READ_BEGIN( ptr, type ) \
EDIT: s/keep in mind the following rules/keep the following rules in mind/