<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[boost fetch_add]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich würde gerne aus boost::atomic fetch_add oder fetch_sub benutzen.<br />
Allerdings klappt das nicht, mein compiler schreit mit fecht_add is not a valid member of boost::atomics::atomic&lt;T&gt;</p>
<p>ich dachte ganz trivial das so zu benutzen:</p>
<pre><code>boost::atomic&lt;bool&gt; myAtomicBool;

myAtomicBool.fetch_add( /*hier stehen die parameter*/ );
</code></pre>
<p>warum klappt das nicht? Wie kann ich fetch_add nutzen?</p>
<p>Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/335669/boost-fetch_add</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 08:40:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/335669.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 03 Dec 2015 12:50:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to boost fetch_add on Thu, 03 Dec 2015 12:50:58 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich würde gerne aus boost::atomic fetch_add oder fetch_sub benutzen.<br />
Allerdings klappt das nicht, mein compiler schreit mit fecht_add is not a valid member of boost::atomics::atomic&lt;T&gt;</p>
<p>ich dachte ganz trivial das so zu benutzen:</p>
<pre><code>boost::atomic&lt;bool&gt; myAtomicBool;

myAtomicBool.fetch_add( /*hier stehen die parameter*/ );
</code></pre>
<p>warum klappt das nicht? Wie kann ich fetch_add nutzen?</p>
<p>Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2478034</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2478034</guid><dc:creator><![CDATA[babmo]]></dc:creator><pubDate>Thu, 03 Dec 2015 12:50:58 GMT</pubDate></item><item><title><![CDATA[Reply to boost fetch_add on Thu, 03 Dec 2015 12:51:31 GMT]]></title><description><![CDATA[<p>Vielleicht machst du was falsch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2478035</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2478035</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Thu, 03 Dec 2015 12:51:31 GMT</pubDate></item><item><title><![CDATA[Reply to boost fetch_add on Thu, 03 Dec 2015 13:14:46 GMT]]></title><description><![CDATA[<p>Danke. Darauf wäre ich nicht gekommen.</p>
<p>Anbei ein Minimalbeispiel - vielleicht bekomme ich dann Hilfe...</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;boost/atomic.hpp&gt;
int main()
{

	boost::atomic&lt;bool&gt; myAtomicBool(false);

	myAtomicBool.fetch_add(true, boost::memory_order_seq_cst);

	std::cout &lt;&lt; &quot;Finished test&quot; &lt;&lt; std::endl;
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2478038</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2478038</guid><dc:creator><![CDATA[babmo]]></dc:creator><pubDate>Thu, 03 Dec 2015 13:14:46 GMT</pubDate></item><item><title><![CDATA[Reply to boost fetch_add on Thu, 03 Dec 2015 13:33:08 GMT]]></title><description><![CDATA[<p>Die Memberfunktion <code>fetch_add</code> gibt es nur für Integer Types, aber nicht für <code>bool</code> . Also entweder <code>boost::atomic&lt;int&gt;</code> verwenden wenn wirklich Addition gefragt ist oder eine der exchange Funktionen nutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2478039</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2478039</guid><dc:creator><![CDATA[sebi707]]></dc:creator><pubDate>Thu, 03 Dec 2015 13:33:08 GMT</pubDate></item><item><title><![CDATA[Reply to boost fetch_add on Thu, 03 Dec 2015 13:41:05 GMT]]></title><description><![CDATA[<p>Danke. MVerstehe ich Dich richtig dass für bool ein exchange atomar und gleichbedeutend mit einem fetch_add für integrale typen ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2478041</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2478041</guid><dc:creator><![CDATA[babmo]]></dc:creator><pubDate>Thu, 03 Dec 2015 13:41:05 GMT</pubDate></item><item><title><![CDATA[Reply to boost fetch_add on Thu, 03 Dec 2015 13:50:02 GMT]]></title><description><![CDATA[<p>Naja exchange, also austauschen, ist was grundlegend anderes als eine Addition. In normalem Code würdest du ja auch kein</p>
<pre><code>bool flag = ...;
flag += true;
</code></pre>
<p>schreiben. Sondern eher etwas wie:</p>
<pre><code>flag = true;

// Oder auch:
if(flag == false)
  flag = true;
</code></pre>
<p>Ersteres wäre ein &quot;exchange&quot;, der Wert wird ersetzt, egal wie der Wert vorher war. Das zweite ist ein &quot;compare exchange&quot;, der Wert wird nur dann ersetzt wenn er bereits einen bestimmten Wert hat. Dafür gibt es in boost auch die Funktionen <code>compare_exchange_weak</code> und <code>compare_exchange_strong</code> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2478042</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2478042</guid><dc:creator><![CDATA[sebi707]]></dc:creator><pubDate>Thu, 03 Dec 2015 13:50:02 GMT</pubDate></item><item><title><![CDATA[Reply to boost fetch_add on Thu, 03 Dec 2015 13:52:38 GMT]]></title><description><![CDATA[<p>Korrektur: Eigentlich ist das erste Beispiel gar kein exchange sondern einfach ein store. Bei einem exchange kriegt man noch als zusätzliche Info was der vorherige Wert war. Atomar sind aber alle diese Operationen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2478043</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2478043</guid><dc:creator><![CDATA[sebi707]]></dc:creator><pubDate>Thu, 03 Dec 2015 13:52:38 GMT</pubDate></item><item><title><![CDATA[Reply to boost fetch_add on Thu, 03 Dec 2015 14:03:52 GMT]]></title><description><![CDATA[<p>Danke weiterhin. Ich hätte eine Folgefrage:<br />
Ist denn der Operator &quot;!&quot; atomar? Also ist folgendes gänzlich atomar?</p>
<pre><code>boost::atomic&lt;bool&gt; myAtomicBool(false);
if (!myAtomicBool.load())
   //...
</code></pre>
<p>myAtomicBool.load() ist atomar wie ich vermute. Aber ist die Negation auch Atomar in Kombination?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2478044</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2478044</guid><dc:creator><![CDATA[babmo]]></dc:creator><pubDate>Thu, 03 Dec 2015 14:03:52 GMT</pubDate></item><item><title><![CDATA[Reply to boost fetch_add on Thu, 03 Dec 2015 14:28:13 GMT]]></title><description><![CDATA[<p>Nein es ist nicht atomar, ist aber auch gar nicht notwendig. Der Wert aus deinem atomic bool wird genau einmal gelesen und damit dein Vergleich angestellt. Ob sich der tatsächliche Wert in der Zwischenzeit geändert hat sollte keine Rolle spielen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2478046</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2478046</guid><dc:creator><![CDATA[sebi707]]></dc:creator><pubDate>Thu, 03 Dec 2015 14:28:13 GMT</pubDate></item></channel></rss>