File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 2736
2736
resulting from this is performed.
2737
2737
\end {note }
2738
2738
2739
+ \pnum
2740
+ \begin {example }
2741
+ \begin {codeblock }
2742
+ template<typename T> class atomic_list {
2743
+ struct node {
2744
+ T t;
2745
+ shared_ptr<node> next;
2746
+ };
2747
+ atomic<shared_ptr<node>> head;
2748
+
2749
+ public:
2750
+ auto find(T t) const {
2751
+ auto p = head.load();
2752
+ while (p && p->t != t)
2753
+ p = p->next;
2754
+
2755
+ return shared_ptr<node>(move(p));
2756
+ }
2757
+
2758
+ void push_front(T t) {
2759
+ auto p = make_shared<node>();
2760
+ p->t = t;
2761
+ p->next = head;
2762
+ while (!head.compare_exchange_weak(p->next, p)) {}
2763
+ }
2764
+ };
2765
+ \end {codeblock }
2766
+ \end {example }
2767
+
2739
2768
\rSec 3[util.smartptr.atomic.shared]{Partial specialization for \tcode {shared_ptr}}
2740
2769
\indexlibraryglobal {atomic<shared_ptr<T>>}%
2741
2770
\begin {codeblock }
You can’t perform that action at this time.
0 commit comments