Change sync::rwlock to use atomics for read_count/read_mode instead of locking #7066
Labels
A-concurrency
Area: Concurrency
I-slow
Issue: Problems and improvements with respect to performance of generated code.
The rwlocks are implemented following the algorithm described here: http://en.wikipedia.org/wiki/Readers-writers_problem#The_third_readers-writers_problem , which has a note:
Note that sections protected by counter_mutex could be replaced by a suitable fetch-and-add atomic instruction, saving two potential context switches in reader's code.
I should implement this, convince myself that it's right, and profile its performance against the old version.
You might argue that doing this the more clever way makes the code less maintainable, that it might accidentally have a bug that would be a lot harder to find. This is possible, although I might argue in response that the logic should never need to be changed, so if I get it right, it will be right forever. We'll have to see how much of a performance improvement it is.
The text was updated successfully, but these errors were encountered: