Struct ThreadSafeFreelist::Node¶
Defined in File pool_allocator.hpp
Nested Relationships¶
This struct is a nested type of Class ThreadSafeFreelist.
Struct Documentation¶
-
struct
ripple::ThreadSafeFreelist
::
Node
¶ The next pointer for the node is atomic because the thread sanitizer says that there is a data race for the following situation:
When pop_front starts in one thread and reads the next pointer from the head, but another thread does also does a pop_front, completes first, and therefore moves the _head. The other thread then does a push_front, and both threads will be trying to perform the compare_exchange. However, because of the tagging, the pop thread will have an invalid tag, so the compare_exchange will fail for the pop thread, but will succeed for the pushing thread, since it has the correct head. The failed popping thread will then try again, and everything is fine. It looks as follows:
Thread 1 Thread 2 | | pop_front() | | | read head->next | | pop_front() | | | read head->next | | | compare_exchange success, tag++ | | | push_front() | | data race on data race on write head->next write head->next | | compare_exchange compare_exhange always fails always succeeds, tag++ | | | return try again | read head->next | | | compare_exchange | succeeds, tag++ |
While this doesn’t cause any problems, we just make the next pointer atomic and use it with relaxed ordering, which doesn’t reduce performance or increase the storage requirement.