Single Link Sync

Suppose I have a sorted, simply connected list of N integers that do not contain duplicates, and k streams (where k <lt; N), each of which is trying to insert some integer (larger than the head of the node) into the list.

Is it possible to synchronize inserts in such a list so that:

  • A thread can block access to its (immediately) previous node
      (There is no "whole list" lock)
  • No more than O (k) mutexes and variable conditions can be used.
  • Suppression / interruption is not allowed.

?

+3
source share
1 answer

-, - , - - O(N), , , , .

, ( ) , :

  • , cur
  • node ( / cur/cur->next)
  • Atomic op: compare_and_swap(cur->next, new, new->next);
    : if (new->value == next->value) return; // someone beat us to it
    Else: cur = cur->next ( , - ).

.. node , , - , node ( - ), -, (.. N, N+3, N+1, - N+2), , , "" node, - .

; RCU (Read-Copy-Update) .

+3

Source: https://habr.com/ru/post/1795200/


All Articles