[PATCH 2 of 2] Core: add ngx_atomic_store() and ngx_atomic_load()

Piotr Sikora piotrsikora at google.com
Fri Sep 16 21:43:49 UTC 2016


Hey Maxim,

> The "*(lock) == 0" check here is just an optimization, it only
> ensures that the lock is likely to succed.

Yes, and use of the ngx_atomic_load() doesn't affect that.

Namely, in the micro-benchmarks I did (heavy contention - 100 threads
trying to acquire lock, update value, release lock in a loop), there
is no performance lose while using ngx_atomic_load() on x86_64,
whereas removing this optimization resulted in 3x worse performance.

> If the
> check returns a wrong result due to non-atomic load - this won't
> do any harm.

It's not just wrong result but a "data race", which leads to undefined
behavior (at least according to C++11).

Best regards,
Piotr Sikora



More information about the nginx-devel mailing list