Skip to content

Question about possible race condition in compare_exchange #2

@trivigy

Description

@trivigy

Inside compare_exchange_weak function on line 1304 the logic decrements local temporary count by 1 to compensate for the increment that happened to the atomic local temporary at line 1291. As I understand this is necessary in order to keep the invariant of theorem 2 equation 1. However, this type of mutation implies a change to a non-atomic shared referenced value (i.e. the local temporary counter of 'expected'). If for instance, this same 'expected' sptr was passed in multiple compare_exchange calls across several threads, where the execution arrived at line 1304 at the same time, would it not be prone to a possible race condition during expected.cp_header_.counter()--;? Alternatively, what if, while execution compare_exchange_weak, another thread called reset on expected. Right at the same moment when line 1304 is being executed. Same memory location is being modified then. Is this not a possible race condition? I might be missing something in my logic and have not yet implemented a test to try and catch this race condition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions