Shortcuts

Struct ThreadSafeFreelist::Node

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.

Public Members

std::atomic<Node*> next

Pointer to the next node.

Docs

Access comprehensive developer documentation for Ripple

View Docs

Tutorials

Get tutorials to help with understand all features

View Tutorials

Examples

Find examples to help get started

View Examples