<?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::Thread Funktion mit Pointer als Parameter]]></title><description><![CDATA[<p>hi,</p>
<p>ich möchte, dass mein main-thread einen worker Thread startet und erst weiterarbeitet, wenn der worker Thread seinen Initialisierungskram abgeschlossen hat (mittels als Pointer übergebener Semaphore)</p>
<p>main-thread:</p>
<pre><code class="language-cpp">boost::interprocess::interprocess_semaphore *pSemUsbIntPipeOpen = new boost::interprocess::interprocess_semaphore(0);
//start Interrupt thread
m_pIntThrd = new boost::thread(boost::bind(&amp;BoardInterfaceUSB::InterruptThread, pSemUsbIntPipeOpen));
//wait at maximum 1 second for the Thread to start
if (pSemUsbIntPipeOpen-&gt;timed_wait(boost::get_system_time() + boost::posix_time::seconds(1)))
{
...
</code></pre>
<p>worker-Thread:</p>
<pre><code class="language-cpp">void BoardInterfaceUSB::InterruptThread(boost::interprocess::interprocess_semaphore *pSemUsbIntPipeOpen)
{
...
  pSemUsbIntPipeOpen-&gt;post();
...
}
</code></pre>
<p>Beim Compilieren bekomme ich diese kryptischen Fehlermeldungen:</p>
<blockquote>
<p>pointer to member type 'void (BoardInterfaceUSB::)(boost::interprocess::interprocess_semaphore*)' incompatible with object type 'boost::interprocess::interprocess_semaphore' line 333, external location: ..\..\..\common\lib\boost_1_39_0\boost\bind\mem_fn.hpp C/C++ Problem</p>
</blockquote>
<p>mit boost::ref habe ich auch etwas rumexperimentiert. Wenn das hier versuche:</p>
<pre><code class="language-cpp">boost::interprocess::interprocess_semaphore semUsbIntPipeOpen(0);
m_pIntThrd = new boost::thread(boost::bind(&amp;BoardInterfaceUSB::InterruptThread, boost::ref(pSemUsbIntPipeOpen)));
</code></pre>
<p>mit</p>
<pre><code class="language-cpp">void BoardInterfaceUSB::InterruptThread(boost::interprocess::interprocess_semaphore pSemUsbIntPipeOpen)
</code></pre>
<p>bekomme ich die Meldung:</p>
<blockquote>
<p>no matching function for call to 'get_pointer(const boost::interprocess::interprocess_semaphore&amp;)' RaptorLib line 333, external location: ..\..\..\common\lib\boost_1_39_0\boost\bind\mem_fn.hpp C/C++ Problem</p>
</blockquote>
<p>Hat jemand einen Lösungsvorschlag?</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/246788/boost-thread-funktion-mit-pointer-als-parameter</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 19:21:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/246788.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 01 Aug 2009 17:35:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Boost::Thread Funktion mit Pointer als Parameter on Sat, 01 Aug 2009 17:35:06 GMT]]></title><description><![CDATA[<p>hi,</p>
<p>ich möchte, dass mein main-thread einen worker Thread startet und erst weiterarbeitet, wenn der worker Thread seinen Initialisierungskram abgeschlossen hat (mittels als Pointer übergebener Semaphore)</p>
<p>main-thread:</p>
<pre><code class="language-cpp">boost::interprocess::interprocess_semaphore *pSemUsbIntPipeOpen = new boost::interprocess::interprocess_semaphore(0);
//start Interrupt thread
m_pIntThrd = new boost::thread(boost::bind(&amp;BoardInterfaceUSB::InterruptThread, pSemUsbIntPipeOpen));
//wait at maximum 1 second for the Thread to start
if (pSemUsbIntPipeOpen-&gt;timed_wait(boost::get_system_time() + boost::posix_time::seconds(1)))
{
...
</code></pre>
<p>worker-Thread:</p>
<pre><code class="language-cpp">void BoardInterfaceUSB::InterruptThread(boost::interprocess::interprocess_semaphore *pSemUsbIntPipeOpen)
{
...
  pSemUsbIntPipeOpen-&gt;post();
...
}
</code></pre>
<p>Beim Compilieren bekomme ich diese kryptischen Fehlermeldungen:</p>
<blockquote>
<p>pointer to member type 'void (BoardInterfaceUSB::)(boost::interprocess::interprocess_semaphore*)' incompatible with object type 'boost::interprocess::interprocess_semaphore' line 333, external location: ..\..\..\common\lib\boost_1_39_0\boost\bind\mem_fn.hpp C/C++ Problem</p>
</blockquote>
<p>mit boost::ref habe ich auch etwas rumexperimentiert. Wenn das hier versuche:</p>
<pre><code class="language-cpp">boost::interprocess::interprocess_semaphore semUsbIntPipeOpen(0);
m_pIntThrd = new boost::thread(boost::bind(&amp;BoardInterfaceUSB::InterruptThread, boost::ref(pSemUsbIntPipeOpen)));
</code></pre>
<p>mit</p>
<pre><code class="language-cpp">void BoardInterfaceUSB::InterruptThread(boost::interprocess::interprocess_semaphore pSemUsbIntPipeOpen)
</code></pre>
<p>bekomme ich die Meldung:</p>
<blockquote>
<p>no matching function for call to 'get_pointer(const boost::interprocess::interprocess_semaphore&amp;)' RaptorLib line 333, external location: ..\..\..\common\lib\boost_1_39_0\boost\bind\mem_fn.hpp C/C++ Problem</p>
</blockquote>
<p>Hat jemand einen Lösungsvorschlag?</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1753654</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1753654</guid><dc:creator><![CDATA[Martin321]]></dc:creator><pubDate>Sat, 01 Aug 2009 17:35:06 GMT</pubDate></item><item><title><![CDATA[Reply to Boost::Thread Funktion mit Pointer als Parameter on Sat, 01 Aug 2009 18:38:34 GMT]]></title><description><![CDATA[<p>Martin321 schrieb:</p>
<blockquote>
<p>Hat jemand einen Lösungsvorschlag?</p>
</blockquote>
<p>Als zweiten Parameter an <code>boost::bind</code> musst du ein Objekt von Typ <code>BoardInterfaceUSB</code> übergeben. Eine Memberfunktion muss schliesslich auf ein Objekt aufgerufen werden. Der Kompiler denkt nun, dass <code>pSemUsbIntPipeOpen</code> ein Zeiger zu einem solchen Objekt ist, merkt aber, dass die Typen inkompatibel sind.</p>
<p>Noch zwei Fragen an dich:<br />
1. Welche Boost Version verwendest du? In den neueren Versionen ist <code>boost::bind</code> nicht mehr nötig im Konstruktor von <code>boost::thread</code> , da dieser die Argumente selber an ein <code>boost::bind</code> weitergibt. Einfach mal in die Boost.Thread Dokumentation schauen, kam vor ein paar Versionen dazu.<br />
2. Wieso eine Interprozess Semaphore? Ist das wirklich eine Synchronisation zwischen zwei Prozessen?</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1753677</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1753677</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Sat, 01 Aug 2009 18:38:34 GMT</pubDate></item><item><title><![CDATA[Reply to Boost::Thread Funktion mit Pointer als Parameter on Sun, 02 Aug 2009 12:34:20 GMT]]></title><description><![CDATA[<p>hi!</p>
<p>Vielen Dank ersteinmal für deine gute Antwort - hat mich schon ein gutes stück weitergebracht.</p>
<blockquote>
<p>Als zweiten Parameter an boost::bind musst du ein Objekt von Typ BoardInterfaceUSB übergeben. Eine Memberfunktion muss schliesslich auf ein Objekt aufgerufen werden. Der Kompiler denkt nun, dass pSemUsbIntPipeOpen ein Zeiger zu einem solchen Objekt ist, merkt aber, dass die Typen inkompatibel sind.</p>
</blockquote>
<p>Das seh ich ein.</p>
<blockquote>
<p>1. Welche Boost Version verwendest du? In den neueren Versionen ist boost::bind nicht mehr nötig im Konstruktor von boost::thread, da dieser die Argumente selber an ein boost::bind weitergibt. Einfach mal in die Boost.Thread Dokumentation schauen, kam vor ein paar Versionen dazu.</p>
</blockquote>
<p>Ich benutze die aktuelle 1.39 Version. Ich muss aber gestehen, dass die Doc <a href="http://www.boost.org/doc/libs/1_39_0/doc/html/thread.html" rel="nofollow">http://www.boost.org/doc/libs/1_39_0/doc/html/thread.html</a> für mich ziemlich unverständlich und mit zu wenigen Beispielen ist.</p>
<p>Wieso sol ich der Klasse Thread ein Object ohne ein bind vorher geben dürfen?</p>
<blockquote>
<p>Thread Constructor with arguments<br />
template &lt;class F,class A1,class A2,...&gt;<br />
thread(F f,A1 a1,A2 a2,...);</p>
</blockquote>
<blockquote>
<p>2. Wieso eine Interprozess Semaphore? Ist das wirklich eine Synchronisation zwischen zwei Prozessen?</p>
</blockquote>
<p>Da hast du natürlich recht. Vorher hab ich in solchen Situationen immer mit QSemaphore (QT) gearbeitet. Das geht aber bei meinem aktuellen Projekt leider nicht.</p>
<p>Habe meinen Code jetzt auf Condition Variables umgestellt:</p>
<p>Thread:</p>
<pre><code class="language-cpp">void BoardInterfaceUSB::InterruptThread(boost::condition_variable &amp;cond, boost::mutex &amp;mut)

    boost::lock_guard&lt;boost::mutex&gt; lock(mut);
    cond.notify_one();
</code></pre>
<p>Threaderzeugende Methode:</p>
<pre><code class="language-cpp">info(&quot;Creating USB Interrupt Thread&quot;);

        boost::mutex mut;
        boost::unique_lock&lt;boost::mutex&gt; lock(mut);
        boost::condition_variable cond;

            InterruptThread(cond, mut);  //geht
        boost::bind(&amp;BoardInterfaceUSB::InterruptThread, this, cond, mut);  //Fehlermeldung1
        //start Interrupt thread
        m_pIntThrd = new boost::thread(boost::bind(&amp;BoardInterfaceUSB::InterruptThread, this, cond, mut)); //Fehlemeldung 2

        if (cond.timed_wait(lock, boost::get_system_time() + boost::posix_time::seconds(1)))
        {
            info(&quot;Interrupt Thread successfully started&quot;);
        }
        else
{
</code></pre>
<p>Fehlermeldung1: (was mach ich bei dem call by reference falsch?)</p>
<blockquote>
<p>g++ -I..\..\..\common\lib\win\PLXSDK\Include -I..\..\..\common\lib\boost_1_39_0 -O0 -g3 -Wall -c -fmessage-length=0 -osrc\BoardInterfaceUSB.o ..\..\src\BoardInterfaceUSB.cpp<br />
..\..\..\common\lib\boost_1_39_0/boost/thread/win32/condition_variable.hpp: In member function 'virtual void RLIB::BoardInterfaceUSB::OpenDevice()':<br />
..\..\..\common\lib\boost_1_39_0/boost/thread/win32/condition_variable.hpp:299: error: 'boost::condition_variable::condition_variable(boost::condition_variable&amp;)' is private<br />
..\..\src\BoardInterfaceUSB.cpp:161: error: within this context<br />
..\..\src\BoardInterfaceUSB.cpp:161: error: initializing argument 3 of 'boost::_bi::bind_t&lt;R, boost::_mfi::mf2&lt;R, T, A1, A2&gt;, typename boost::_bi::list_av_3&lt;A1, A2, A3&gt;::type&gt; boost::bind(R (T::<em>)(B1, B2), A1, A2, A3) [with R = void, T = RLIB::BoardInterfaceUSB, B1 = boost::condition_variable&amp;, B2 = boost::mutex&amp;, A1 = RLIB::BoardInterfaceUSB</em>, A2 = boost::condition_variable, A3 = boost::mutex]'<br />
In file included from ..\..\..\common\lib\boost_1_39_0/boost/thread/mutex.hpp:14,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread/detail/thread.hpp:11,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread/thread.hpp:22,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread.hpp:13,<br />
from ..\..\src\BoardInterfaceUSB.h:10,<br />
from ..\..\src\BoardInterfaceUSB.cpp:1:<br />
..\..\..\common\lib\boost_1_39_0/boost/noncopyable.hpp: In copy constructor 'boost::mutex::mutex(const boost::mutex&amp;)':<br />
..\..\..\common\lib\boost_1_39_0/boost/noncopyable.hpp:27: error: 'boost::noncopyable_::noncopyable::noncopyable(const boost::noncopyable_::noncopyable&amp;)' is private<br />
..\..\..\common\lib\boost_1_39_0/boost/thread/win32/mutex.hpp:25: error: within this context<br />
..\..\src\BoardInterfaceUSB.cpp: In member function 'virtual void RLIB::BoardInterfaceUSB::OpenDevice()':<br />
..\..\src\BoardInterfaceUSB.cpp:161: note: synthesized method 'boost::mutex::mutex(const boost::mutex&amp;)' first required here<br />
..\..\src\BoardInterfaceUSB.cpp:161: error: initializing argument 4 of 'boost::_bi::bind_t&lt;R, boost::_mfi::mf2&lt;R, T, A1, A2&gt;, typename boost::_bi::list_av_3&lt;A1, A2, A3&gt;::type&gt; boost::bind(R (T::<em>)(B1, B2), A1, A2, A3) [with R = void, T = RLIB::BoardInterfaceUSB, B1 = boost::condition_variable&amp;, B2 = boost::mutex&amp;, A1 = RLIB::BoardInterfaceUSB</em>, A2 = boost::condition_variable, A3 = boost::mutex]'<br />
In file included from ..\..\..\common\lib\boost_1_39_0/boost/bind/bind.hpp:1584,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/bind.hpp:22,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread/detail/thread.hpp:20,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread/thread.hpp:22,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread.hpp:13,<br />
from ..\..\src\BoardInterfaceUSB.h:10,<br />
from ..\..\src\BoardInterfaceUSB.cpp:1:<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind_mf_cc.hpp: In function 'boost::_bi::bind_t&lt;R, boost::_mfi::mf2&lt;R, T, A1, A2&gt;, typename boost::_bi::list_av_3&lt;A1, A2, A3&gt;::type&gt; boost::bind(R (T::<em>)(B1, B2), A1, A2, A3) [with R = void, T = RLIB::BoardInterfaceUSB, B1 = boost::condition_variable&amp;, B2 = boost::mutex&amp;, A1 = RLIB::BoardInterfaceUSB</em>, A2 = boost::condition_variable, A3 = boost::mutex]':<br />
..\..\src\BoardInterfaceUSB.cpp:161: instantiated from here<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind_mf_cc.hpp:71: error: no matching function for call to 'boost::_bi::value<a href="boost::condition%5C_variable" rel="nofollow">boost::condition\_variable</a>::value(boost::_bi::value<a href="boost::condition_variable" rel="nofollow">boost::condition_variable</a>)'<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind.hpp:116: note: candidates are: boost::_bi::value&lt;T&gt;::value(const T&amp;) [with T = boost::condition_variable]<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind.hpp:113: note: boost::_bi::value<a href="boost::condition%5C_variable" rel="nofollow">boost::condition\_variable</a>::value(boost::_bi::value<a href="boost::condition_variable" rel="nofollow">boost::condition_variable</a>&amp;)<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind_mf_cc.hpp:71: error: initializing argument 2 of 'boost::_bi::list3&lt;A1, A2, A3&gt;::list3(A1, A2, A3) [with A1 = boost::_bi::value<a href="RLIB::BoardInterfaceUSB*" rel="nofollow">RLIB::BoardInterfaceUSB*</a>, A2 = boost::_bi::value<a href="boost::condition%5C_variable" rel="nofollow">boost::condition\_variable</a>, A3 = boost::_bi::value<a href="boost::mutex" rel="nofollow">boost::mutex</a>]'<br />
In file included from ..\..\..\common\lib\boost_1_39_0/boost/bind.hpp:22,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread/detail/thread.hpp:20,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread/thread.hpp:22,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread.hpp:13,<br />
from ..\..\src\BoardInterfaceUSB.h:10,<br />
from ..\..\src\BoardInterfaceUSB.cpp:1:<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind.hpp: In constructor 'boost::_bi::value&lt;T&gt;::value(const T&amp;) [with T = boost::condition_variable]':<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind_mf_cc.hpp:71: instantiated from 'boost::_bi::bind_t&lt;R, boost::_mfi::mf2&lt;R, T, A1, A2&gt;, typename boost::_bi::list_av_3&lt;A1, A2, A3&gt;::type&gt; boost::bind(R (T::<em>)(B1, B2), A1, A2, A3) [with R = void, T = RLIB::BoardInterfaceUSB, B1 = boost::condition_variable&amp;, B2 = boost::mutex&amp;, A1 = RLIB::BoardInterfaceUSB</em>, A2 = boost::condition_variable, A3 = boost::mutex]'<br />
..\..\src\BoardInterfaceUSB.cpp:161: instantiated from here<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind.hpp:116: error: no matching function for call to 'boost::condition_variable::condition_variable(const boost::condition_variable&amp;)'<br />
..\..\..\common\lib\boost_1_39_0/boost/thread/win32/condition_variable.hpp:302: note: candidates are: boost::condition_variable::condition_variable()<br />
..\..\..\common\lib\boost_1_39_0/boost/thread/win32/condition_variable.hpp:299: note: boost::condition_variable::condition_variable(boost::condition_variable&amp;)</p>
</blockquote>
<p>Fehlermeldung2:</p>
<blockquote>
<p>g++ -I..\..\..\common\lib\win\PLXSDK\Include -I..\..\..\common\lib\boost_1_39_0 -O0 -g3 -Wall -c -fmessage-length=0 -osrc\BoardInterfaceUSB.o ..\..\src\BoardInterfaceUSB.cpp<br />
..\..\..\common\lib\boost_1_39_0/boost/thread/win32/condition_variable.hpp: In member function 'virtual void RLIB::BoardInterfaceUSB::OpenDevice()':<br />
..\..\..\common\lib\boost_1_39_0/boost/thread/win32/condition_variable.hpp:299: error: 'boost::condition_variable::condition_variable(boost::condition_variable&amp;)' is private<br />
..\..\src\BoardInterfaceUSB.cpp:163: error: within this context<br />
..\..\src\BoardInterfaceUSB.cpp:163: error: initializing argument 3 of 'boost::_bi::bind_t&lt;R, boost::_mfi::mf2&lt;R, T, A1, A2&gt;, typename boost::_bi::list_av_3&lt;A1, A2, A3&gt;::type&gt; boost::bind(R (T::<em>)(B1, B2), A1, A2, A3) [with R = void, T = RLIB::BoardInterfaceUSB, B1 = boost::condition_variable&amp;, B2 = boost::mutex&amp;, A1 = RLIB::BoardInterfaceUSB</em>, A2 = boost::condition_variable, A3 = boost::mutex]'<br />
In file included from ..\..\..\common\lib\boost_1_39_0/boost/thread/mutex.hpp:14,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread/detail/thread.hpp:11,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread/thread.hpp:22,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread.hpp:13,<br />
from ..\..\src\BoardInterfaceUSB.h:10,<br />
from ..\..\src\BoardInterfaceUSB.cpp:1:<br />
..\..\..\common\lib\boost_1_39_0/boost/noncopyable.hpp: In copy constructor 'boost::mutex::mutex(const boost::mutex&amp;)':<br />
..\..\..\common\lib\boost_1_39_0/boost/noncopyable.hpp:27: error: 'boost::noncopyable_::noncopyable::noncopyable(const boost::noncopyable_::noncopyable&amp;)' is private<br />
..\..\..\common\lib\boost_1_39_0/boost/thread/win32/mutex.hpp:25: error: within this context<br />
..\..\src\BoardInterfaceUSB.cpp: In member function 'virtual void RLIB::BoardInterfaceUSB::OpenDevice()':<br />
..\..\src\BoardInterfaceUSB.cpp:163: note: synthesized method 'boost::mutex::mutex(const boost::mutex&amp;)' first required here<br />
..\..\src\BoardInterfaceUSB.cpp:163: error: initializing argument 4 of 'boost::_bi::bind_t&lt;R, boost::_mfi::mf2&lt;R, T, A1, A2&gt;, typename boost::_bi::list_av_3&lt;A1, A2, A3&gt;::type&gt; boost::bind(R (T::<em>)(B1, B2), A1, A2, A3) [with R = void, T = RLIB::BoardInterfaceUSB, B1 = boost::condition_variable&amp;, B2 = boost::mutex&amp;, A1 = RLIB::BoardInterfaceUSB</em>, A2 = boost::condition_variable, A3 = boost::mutex]'<br />
..\..\src\BoardInterfaceUSB.cpp:163: error: no matching function for call to 'boost::_bi::bind_t&lt;void, boost::_mfi::mf2&lt;void, RLIB::BoardInterfaceUSB, boost::condition_variable&amp;, boost::mutex&amp;&gt;, boost::_bi::list3&lt;boost::_bi::value<a href="RLIB::BoardInterfaceUSB*" rel="nofollow">RLIB::BoardInterfaceUSB*</a>, boost::_bi::value<a href="boost::condition%5C_variable" rel="nofollow">boost::condition\_variable</a>, boost::_bi::value<a href="boost::mutex" rel="nofollow">boost::mutex</a> &gt; &gt;::bind_t(boost::_bi::bind_t&lt;void, boost::_mfi::mf2&lt;void, RLIB::BoardInterfaceUSB, boost::condition_variable&amp;, boost::mutex&amp;&gt;, boost::_bi::list3&lt;boost::_bi::value<a href="RLIB::BoardInterfaceUSB*" rel="nofollow">RLIB::BoardInterfaceUSB*</a>, boost::_bi::value<a href="boost::condition%5C_variable" rel="nofollow">boost::condition\_variable</a>, boost::_bi::value<a href="boost::mutex" rel="nofollow">boost::mutex</a> &gt; &gt;)'<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind.hpp:859: note: candidates are: boost::_bi::bind_t&lt;R, F, L&gt;::bind_t(F, const L&amp;) [with R = void, F = boost::_mfi::mf2&lt;void, RLIB::BoardInterfaceUSB, boost::condition_variable&amp;, boost::mutex&amp;&gt;, L = boost::_bi::list3&lt;boost::_bi::value<a href="RLIB::BoardInterfaceUSB*" rel="nofollow">RLIB::BoardInterfaceUSB*</a>, boost::_bi::value<a href="boost::condition%5C_variable" rel="nofollow">boost::condition\_variable</a>, boost::_bi::value<a href="boost::mutex" rel="nofollow">boost::mutex</a> &gt;]<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind.hpp:854: note: boost::_bi::bind_t&lt;void, boost::_mfi::mf2&lt;void, RLIB::BoardInterfaceUSB, boost::condition_variable&amp;, boost::mutex&amp;&gt;, boost::_bi::list3&lt;boost::_bi::value<a href="RLIB::BoardInterfaceUSB*" rel="nofollow">RLIB::BoardInterfaceUSB*</a>, boost::_bi::value<a href="boost::condition%5C_variable" rel="nofollow">boost::condition\_variable</a>, boost::_bi::value<a href="boost::mutex" rel="nofollow">boost::mutex</a> &gt; &gt;::bind_t(boost::_bi::bind_t&lt;void, boost::_mfi::mf2&lt;void, RLIB::BoardInterfaceUSB, boost::condition_variable&amp;, boost::mutex&amp;&gt;, boost::_bi::list3&lt;boost::_bi::value<a href="RLIB::BoardInterfaceUSB*" rel="nofollow">RLIB::BoardInterfaceUSB*</a>, boost::_bi::value<a href="boost::condition%5C_variable" rel="nofollow">boost::condition\_variable</a>, boost::_bi::value<a href="boost::mutex" rel="nofollow">boost::mutex</a> &gt; &gt;&amp;)<br />
..\..\src\BoardInterfaceUSB.cpp:163: error: initializing argument 1 of 'boost::thread::thread(F, typename boost::disable_if&lt;boost::is_convertible&lt;T&amp;, boost::detail::thread_move_t&lt;T&gt; &gt;, boost::thread::dummy*&gt;::type) [with F = boost::_bi::bind_t&lt;void, boost::_mfi::mf2&lt;void, RLIB::BoardInterfaceUSB, boost::condition_variable&amp;, boost::mutex&amp;&gt;, boost::_bi::list3&lt;boost::_bi::value<a href="RLIB::BoardInterfaceUSB*" rel="nofollow">RLIB::BoardInterfaceUSB*</a>, boost::_bi::value<a href="boost::condition%5C_variable" rel="nofollow">boost::condition\_variable</a>, boost::_bi::value<a href="boost::mutex" rel="nofollow">boost::mutex</a> &gt; &gt;]'<br />
In file included from ..\..\..\common\lib\boost_1_39_0/boost/bind/bind.hpp:1584,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/bind.hpp:22,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread/detail/thread.hpp:20,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread/thread.hpp:22,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread.hpp:13,<br />
from ..\..\src\BoardInterfaceUSB.h:10,<br />
from ..\..\src\BoardInterfaceUSB.cpp:1:<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind_mf_cc.hpp: In function 'boost::_bi::bind_t&lt;R, boost::_mfi::mf2&lt;R, T, A1, A2&gt;, typename boost::_bi::list_av_3&lt;A1, A2, A3&gt;::type&gt; boost::bind(R (T::<em>)(B1, B2), A1, A2, A3) [with R = void, T = RLIB::BoardInterfaceUSB, B1 = boost::condition_variable&amp;, B2 = boost::mutex&amp;, A1 = RLIB::BoardInterfaceUSB</em>, A2 = boost::condition_variable, A3 = boost::mutex]':<br />
..\..\src\BoardInterfaceUSB.cpp:163: instantiated from here<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind_mf_cc.hpp:71: error: no matching function for call to 'boost::_bi::value<a href="boost::condition%5C_variable" rel="nofollow">boost::condition\_variable</a>::value(boost::_bi::value<a href="boost::condition_variable" rel="nofollow">boost::condition_variable</a>)'<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind.hpp:116: note: candidates are: boost::_bi::value&lt;T&gt;::value(const T&amp;) [with T = boost::condition_variable]<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind.hpp:113: note: boost::_bi::value<a href="boost::condition%5C_variable" rel="nofollow">boost::condition\_variable</a>::value(boost::_bi::value<a href="boost::condition_variable" rel="nofollow">boost::condition_variable</a>&amp;)<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind_mf_cc.hpp:71: error: initializing argument 2 of 'boost::_bi::list3&lt;A1, A2, A3&gt;::list3(A1, A2, A3) [with A1 = boost::_bi::value<a href="RLIB::BoardInterfaceUSB*" rel="nofollow">RLIB::BoardInterfaceUSB*</a>, A2 = boost::_bi::value<a href="boost::condition%5C_variable" rel="nofollow">boost::condition\_variable</a>, A3 = boost::_bi::value<a href="boost::mutex" rel="nofollow">boost::mutex</a>]'<br />
In file included from ..\..\..\common\lib\boost_1_39_0/boost/bind.hpp:22,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread/detail/thread.hpp:20,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread/thread.hpp:22,<br />
from ..\..\..\common\lib\boost_1_39_0/boost/thread.hpp:13,<br />
from ..\..\src\BoardInterfaceUSB.h:10,<br />
from ..\..\src\BoardInterfaceUSB.cpp:1:<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind.hpp: In constructor 'boost::_bi::value&lt;T&gt;::value(const T&amp;) [with T = boost::condition_variable]':<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind_mf_cc.hpp:71: instantiated from 'boost::_bi::bind_t&lt;R, boost::_mfi::mf2&lt;R, T, A1, A2&gt;, typename boost::_bi::list_av_3&lt;A1, A2, A3&gt;::type&gt; boost::bind(R (T::<em>)(B1, B2), A1, A2, A3) [with R = void, T = RLIB::BoardInterfaceUSB, B1 = boost::condition_variable&amp;, B2 = boost::mutex&amp;, A1 = RLIB::BoardInterfaceUSB</em>, A2 = boost::condition_variable, A3 = boost::mutex]'<br />
..\..\src\BoardInterfaceUSB.cpp:163: instantiated from here<br />
..\..\..\common\lib\boost_1_39_0/boost/bind/bind.hpp:116: error: no matching function for call to 'boost::condition_variable::condition_variable(const boost::condition_variable&amp;)'<br />
..\..\..\common\lib\boost_1_39_0/boost/thread/win32/condition_variable.hpp:302: note: candidates are: boost::condition_variable::condition_variable()<br />
..\..\..\common\lib\boost_1_39_0/boost/thread/win32/condition_variable.hpp:299: note: boost::condition_variable::condition_variable(boost::condition_variable&amp;)</p>
</blockquote>
<p>Gruß<br />
Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1753969</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1753969</guid><dc:creator><![CDATA[Martin321]]></dc:creator><pubDate>Sun, 02 Aug 2009 12:34:20 GMT</pubDate></item><item><title><![CDATA[Reply to Boost::Thread Funktion mit Pointer als Parameter on Sun, 02 Aug 2009 12:57:55 GMT]]></title><description><![CDATA[<p>Martin321 schrieb:</p>
<blockquote>
<p>Wieso sol ich der Klasse Thread ein Object ohne ein bind vorher geben dürfen?</p>
</blockquote>
<p>Einfach die Doku lesen:<br />
<a href="http://www.boost.org/doc/libs/1_39_0/doc/html/thread/thread_management.html#thread.thread_management.thread.multiple_argument_constructor" rel="nofollow">http://www.boost.org/doc/libs/1_39_0/doc/html/thread/thread_management.html#thread.thread_management.thread.multiple_argument_constructor</a></p>
<blockquote>
<p>Effects:<br />
As if thread(boost::bind(f,a1,a2,...)). Consequently, f and each an are copied into internal storage for access by the new thread.</p>
</blockquote>
<p>Zu deinem neuen Problem:<br />
<code>boost::condition_variable</code> und <code>boost::mutex</code> sind nicht kopierbar. Jedes Argument, welches man allerdings an <code>boost::bind</code> übergibt, wird kopiert. Falls du eine Referenz übergeben willst, musst du diese mit<a href="http://www.boost.org/doc/libs/1_39_0/doc/html/ref.html" rel="nofollow"> <code>boost::ref</code> </a>wrappen.</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1753978</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1753978</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Sun, 02 Aug 2009 12:57:55 GMT</pubDate></item><item><title><![CDATA[Reply to Boost::Thread Funktion mit Pointer als Parameter on Wed, 05 Aug 2009 10:02:36 GMT]]></title><description><![CDATA[<p>hi,</p>
<p>Dravere schrieb:</p>
<blockquote>
<p>Martin321 schrieb:</p>
<blockquote>
<p>Wieso sol ich der Klasse Thread ein Object ohne ein bind vorher geben dürfen?</p>
</blockquote>
<p>Einfach die Doku lesen:<br />
<a href="http://www.boost.org/doc/libs/1_39_0/doc/html/thread/thread_management.html#thread.thread_management.thread.multiple_argument_constructor" rel="nofollow">http://www.boost.org/doc/libs/1_39_0/doc/html/thread/thread_management.html#thread.thread_management.thread.multiple_argument_constructor</a></p>
<blockquote>
<p>Effects:<br />
As if thread(boost::bind(f,a1,a2,...)). Consequently, f and each an are copied into internal storage for access by the new thread.</p>
</blockquote>
<p>Zu deinem neuen Problem:<br />
<code>boost::condition_variable</code> und <code>boost::mutex</code> sind nicht kopierbar. Jedes Argument, welches man allerdings an <code>boost::bind</code> übergibt, wird kopiert. Falls du eine Referenz übergeben willst, musst du diese mit<a href="http://www.boost.org/doc/libs/1_39_0/doc/html/ref.html" rel="nofollow"> <code>boost::ref</code> </a>wrappen.</p>
<p>Grüssli</p>
</blockquote>
<p>Vielen Dank nochmal! Mit deiner Hilfe hab ichs endlich geschafft <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Habe es jetzt so gelöst:</p>
<pre><code class="language-cpp">m_pIntThrd = new boost::thread(BoardInterfaceUSB::InterruptThread, this, boost::ref(m_bDeviceOpened), boost::ref(bThreadRdy), boost::ref(condUsbIntThrdRdy), boost::ref(mtxUsbIntThread));
</code></pre>
<p>...beim googlen nach Doku für die Condition variable ist nicht viel bei herum gekommen. Die Boost Doku finde ich immer noch sehr unverständlich und nicht ausreichend. Beim Testen hab ich mir ein Testprogramm geschrieben, welches viellleicht anderen auch hilfreich sein kann.</p>
<p>Achtung: im Testprogramm, ist der InterruptThread keine Memberfunktion, daher fehlt das 'this'!</p>
<p>Wenn man in der 2. Zeile von InterruptThread das return einkommentiert, wird ein Fehler simuliert und das timed_wait auf die condition variable bricht nach 10 Sekunden ab.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;boost/thread.hpp&gt;
using namespace std;

void InterruptThread(bool &amp;m_bDeviceOpened, bool &amp;bThreadRdy, boost::condition_variable &amp;condUsbIntThrdRdy,
                     boost::mutex &amp;mtxbThreadRdy)
{
    //	if (!init()) // Do some critical stuff here
    //		return;

    //wait until the mainThread unlocks the mutex
    boost::lock_guard&lt;boost::mutex&gt; lock(mtxbThreadRdy);
    // mutex is locked now

    bThreadRdy = true;
    mtxbThreadRdy.unlock();

    cout &lt;&lt; &quot;IntThread:: Notifying mainThread\n&quot;;
    condUsbIntThrdRdy.notify_one();

    while (m_bDeviceOpened)
    {
        std::cout &lt;&lt; &quot;IntThreadRunning\n&quot;;
        boost::this_thread::sleep(boost::posix_time::milliseconds(2000));
    }

    cout &lt;&lt; &quot;IntThread:: Finished!\n&quot;;
}

int main()
{
    cout &lt;&lt; &quot;mainThread: Started&quot; &lt;&lt; endl;

    bool m_bDeviceOpened = true;
    bool bThreadRdy = false;
    boost::thread *m_pIntThrd;

    boost::mutex mtxUsbIntThread;
    boost::condition_variable condUsbIntThrdRdy;

    boost::unique_lock&lt;boost::mutex&gt; lock(mtxUsbIntThread);
    // mutex is locked now

    //start Thread
    m_pIntThrd = new boost::thread(&amp;InterruptThread, boost::ref(m_bDeviceOpened), boost::ref(bThreadRdy), boost::ref(condUsbIntThrdRdy), boost::ref(mtxUsbIntThread));
    cout &lt;&lt; &quot;mainThread: Started Interrupt Thread. Waiting for 1 s\n&quot;;
    boost::this_thread::sleep(boost::posix_time::milliseconds(1000));

    cout &lt;&lt; &quot;mainThread: Waiting for condition\n&quot;;

    // unlock Mtx (implicitly) and wait until being notified or the time expires
    if (!condUsbIntThrdRdy.timed_wait(lock, boost::get_system_time() + boost::posix_time::seconds(10)))
    {
        cout &lt;&lt; &quot;mainThread: Time is Up! Starting the Thread failed!\n&quot;;
    }
    else
    {
		cout &lt;&lt; &quot;mainThread: Interrupt Thread successfully started\n&quot;;
    }

    boost::this_thread::sleep(boost::posix_time::milliseconds(10000));      //wait 10 secs

    cout &lt;&lt; &quot;mainThread: Stopping Interrupt Thread\n&quot;;
    m_bDeviceOpened = false;
    m_pIntThrd-&gt;join();

    return 0;
}
</code></pre>
<p>Noch etwas zur BoostLib Doku für cond vars: <a href="http://www.boost.org/doc/libs/1_39_0/doc/html/thread/synchronization.html#thread.synchronization.condvar_ref" rel="nofollow">http://www.boost.org/doc/libs/1_39_0/doc/html/thread/synchronization.html#thread.synchronization.condvar_ref</a></p>
<p>weil in</p>
<pre><code class="language-cpp">prepare_data();
    {
        boost::lock_guard&lt;boost::mutex&gt; lock(mut);
        data_ready=true;
    }
</code></pre>
<p>der lock in Klammern gesetzt wird, wird das Objekt lock am Ende der Klammern zerstört und der dahinterliegende mutex mut automatisch unlocked.<br />
...das hat mich gut eine Stunde gekostet <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Viele Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1755591</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1755591</guid><dc:creator><![CDATA[Martin321]]></dc:creator><pubDate>Wed, 05 Aug 2009 10:02:36 GMT</pubDate></item></channel></rss>