I need to ensure that a counter variable (say i) is not updated by more than one thread at a time. I have written a ring buffer and have one thread reading and one writing. The only time they cross swords is when they update the counter variable. I know I could use a mutex but I would much rather avoid using locks if at all possible for performance reasons.
Are there any alternatives to using a mutex here?