<div dir="auto"><p dir="ltr">You could have an API along the lines of:<br>```</p><p dir="ltr">bool accessed = ptr.try_access([] (T&amp; ref) { ref.function1(); ref.function2(); });</p><p dir="ltr">```</p><p dir="ltr">
But I am not sure if we are getting any advantage over shared_ptr. Is there a reference implementation that can show how it works and how it solves the problem better/being more lightweight than shared_ptr?</p><p dir="ltr"><br></p><p dir="ltr">// Robin</p></div>
<br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 24, 2025, 03:11 Thiago Macieira via Std-Proposals &lt;<a href="mailto:std-proposals@lists.isocpp.org" target="_blank" rel="noreferrer">std-proposals@lists.isocpp.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sunday, 23 February 2025 19:40:38 Brasilia Standard Time Henry Miller via <br>
Std-Proposals wrote:<br>
&gt; What this gives us that operator-&gt;() doesn&#39;t is direct knowledge when the<br>
&gt; function is done and thus an obvious place to release the lock.<br>
<br>
That&#39;s hardly a correct assumption. No one would write:<br>
<br>
  mutex.lock();<br>
  ptr-&gt;function1();<br>
  mutex.unlock();<br>
  mutex.lock();<br>
  ptr-&gt;function2();<br>
  mutex.unlock();<br>
<br>
Aside from the extra code this is generating and the possibly strain this is <br>
putting on the cache traffic, the fact that you unlocked between function1 and <br>
function2 implies the state may have completely changed. There may be cases <br>
where this is an acceptable behaviour, but in the general case it won&#39;t be, <br>
and that&#39;s why I said assuming the end of the expression is the correct place <br>
to unlock.<br>
<br>
In the majority of cases, I expect a lock to need to be held across multiple <br>
invocations, so one must either get a locked proxy object that prevents the <br>
state from changing underneath the object, or must explicitly lock themselves. <br>
If the latter, an automatic lock by the class would be either superfluous or <br>
would be a trigger for deadlocks.<br>
<br>
-- <br>
Thiago Macieira - thiago (AT) <a href="http://macieira.info" rel="noreferrer noreferrer noreferrer" target="_blank">macieira.info</a> - thiago (AT) <a href="http://kde.org" rel="noreferrer noreferrer noreferrer" target="_blank">kde.org</a><br>
  Principal Engineer - Intel DCAI Platform &amp; System Engineering<br>
<br>
<br>
<br>
-- <br>
Std-Proposals mailing list<br>
<a href="mailto:Std-Proposals@lists.isocpp.org" rel="noreferrer noreferrer" target="_blank">Std-Proposals@lists.isocpp.org</a><br>
<a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer noreferrer noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><br>
</blockquote></div>

