<?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[Problem mit boost::thread]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;boost/thread/mutex.hpp&gt;
#include &lt;boost/thread/thread.hpp&gt;

boost::mutex io_mutex; // The iostreams are not guaranteed to be thread-safe!
const size_t myarray_max_size = 100;
unsigned long myarray[myarray_max_size];
size_t myarray_size;

class counter
{
public:
    counter() : count(0) { }

    int increment() {
        boost::mutex::scoped_lock scoped_lock(mutex);
        return ++count;
    }

private:
    boost::mutex mutex;
    int count;
};

counter c;

class myclass
{
	void change_count()
	{
		int thread_number = c.increment();

		do {
			const size_t mylocalarray_size = 2;
			unsigned long mylocalarray[mylocalarray_size];
			for (size_t i = 0; i &lt; mylocalarray_size; ++i)
			{
				mylocalarray[i] = rand();

				boost::xtime xt;
				boost::xtime_get(&amp;xt, boost::TIME_UTC);
				xt.nsec += 1000;
				boost::thread::sleep(xt);
			}

			boost::mutex::scoped_lock scoped_lock(io_mutex);
			std::cout &lt;&lt; &quot;Thread #&quot; &lt;&lt; thread_number &lt;&lt; std::endl;
			for (size_t i = 0; (myarray_size &lt; myarray_max_size) &amp;&amp; (i &lt; mylocalarray_size); ++i, ++myarray_size)
				myarray[myarray_size] = mylocalarray[i];
		} while (myarray_size &lt; myarray_max_size);
	}

public:
	void main()
	{
		myarray_size = 0;

		const int num_threads = 2;
		boost::thread_group thrds;
		for (int i = 0; i &lt; num_threads; ++i)
			thrds.create_thread(&amp;myclass::change_count);

		do {
			boost::xtime xt;
			boost::xtime_get(&amp;xt, boost::TIME_UTC);
			xt.nsec += 1000;
			boost::thread::sleep(xt);

			boost::mutex::scoped_lock scoped_lock(io_mutex);
		} while (myarray_size &lt; myarray_max_size);

		thrds.join_all();

		std::cout &lt;&lt; &quot;Alle beendet&quot; &lt;&lt; std::endl;
	}
};

int main()
{
	myclass a;
	a.main();

	char c;
	std::cin &gt;&gt; c;
}
</code></pre>
<p>macht folgenden Fehler</p>
<pre><code>1&gt;C:\Users\Bla\Documents\Visual Studio 2010\Projects\boost_1_43_0\boost/thread/detail/thread.hpp(59): error C2064: term does not evaluate to a function taking 0 arguments
1&gt;          C:\Users\Bla\Documents\Visual Studio 2010\Projects\boost_1_43_0\boost/thread/detail/thread.hpp(58) : while compiling class template member function 'void boost::detail::thread_data&lt;F&gt;::run(void)'
1&gt;          with
1&gt;          [
1&gt;              F=void (__cdecl myclass::* )(void)
1&gt;          ]
1&gt;          C:\Users\Bla\Documents\Visual Studio 2010\Projects\boost_1_43_0\boost/thread/detail/thread.hpp(129) : see reference to class template instantiation 'boost::detail::thread_data&lt;F&gt;' being compiled
1&gt;          with
1&gt;          [
1&gt;              F=void (__cdecl myclass::* )(void)
1&gt;          ]
1&gt;          C:\Users\Bla\Documents\Visual Studio 2010\Projects\boost_1_43_0\boost/thread/detail/thread.hpp(160) : see reference to function template instantiation 'boost::detail::thread_data_ptr boost::thread::make_thread_info&lt;F&amp;&gt;(void)' being compiled
1&gt;          with
1&gt;          [
1&gt;              F=void (__cdecl myclass::* )(void)
1&gt;          ]
1&gt;          C:\Users\Bla\Documents\Visual Studio 2010\Projects\boost_1_43_0\boost/thread/detail/thread_group.hpp(39) : see reference to function template instantiation 'boost::thread::thread&lt;F&gt;(F,boost::thread::dummy *)' being compiled
1&gt;          with
1&gt;          [
1&gt;              F=void (__cdecl myclass::* )(void)
1&gt;          ]
1&gt;          main.cpp(148) : see reference to function template instantiation 'boost::thread *boost::thread_group::create_thread&lt;void(__cdecl myclass::* )(void)&gt;(F)' being compiled
1&gt;          with
1&gt;          [
1&gt;              F=void (__cdecl myclass::* )(void)
1&gt;          ]
</code></pre>
<p>(Zeilennummern stimmen nicht)</p>
<p>Das Problem ist, dass die Thread-Funktion eine Memberfunktion meiner Klasse ist. Wie kann ich das lösen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/271953/problem-mit-boost-thread</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 03:22:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/271953.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 06 Aug 2010 19:53:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit boost::thread on Fri, 06 Aug 2010 19:53:41 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;boost/thread/mutex.hpp&gt;
#include &lt;boost/thread/thread.hpp&gt;

boost::mutex io_mutex; // The iostreams are not guaranteed to be thread-safe!
const size_t myarray_max_size = 100;
unsigned long myarray[myarray_max_size];
size_t myarray_size;

class counter
{
public:
    counter() : count(0) { }

    int increment() {
        boost::mutex::scoped_lock scoped_lock(mutex);
        return ++count;
    }

private:
    boost::mutex mutex;
    int count;
};

counter c;

class myclass
{
	void change_count()
	{
		int thread_number = c.increment();

		do {
			const size_t mylocalarray_size = 2;
			unsigned long mylocalarray[mylocalarray_size];
			for (size_t i = 0; i &lt; mylocalarray_size; ++i)
			{
				mylocalarray[i] = rand();

				boost::xtime xt;
				boost::xtime_get(&amp;xt, boost::TIME_UTC);
				xt.nsec += 1000;
				boost::thread::sleep(xt);
			}

			boost::mutex::scoped_lock scoped_lock(io_mutex);
			std::cout &lt;&lt; &quot;Thread #&quot; &lt;&lt; thread_number &lt;&lt; std::endl;
			for (size_t i = 0; (myarray_size &lt; myarray_max_size) &amp;&amp; (i &lt; mylocalarray_size); ++i, ++myarray_size)
				myarray[myarray_size] = mylocalarray[i];
		} while (myarray_size &lt; myarray_max_size);
	}

public:
	void main()
	{
		myarray_size = 0;

		const int num_threads = 2;
		boost::thread_group thrds;
		for (int i = 0; i &lt; num_threads; ++i)
			thrds.create_thread(&amp;myclass::change_count);

		do {
			boost::xtime xt;
			boost::xtime_get(&amp;xt, boost::TIME_UTC);
			xt.nsec += 1000;
			boost::thread::sleep(xt);

			boost::mutex::scoped_lock scoped_lock(io_mutex);
		} while (myarray_size &lt; myarray_max_size);

		thrds.join_all();

		std::cout &lt;&lt; &quot;Alle beendet&quot; &lt;&lt; std::endl;
	}
};

int main()
{
	myclass a;
	a.main();

	char c;
	std::cin &gt;&gt; c;
}
</code></pre>
<p>macht folgenden Fehler</p>
<pre><code>1&gt;C:\Users\Bla\Documents\Visual Studio 2010\Projects\boost_1_43_0\boost/thread/detail/thread.hpp(59): error C2064: term does not evaluate to a function taking 0 arguments
1&gt;          C:\Users\Bla\Documents\Visual Studio 2010\Projects\boost_1_43_0\boost/thread/detail/thread.hpp(58) : while compiling class template member function 'void boost::detail::thread_data&lt;F&gt;::run(void)'
1&gt;          with
1&gt;          [
1&gt;              F=void (__cdecl myclass::* )(void)
1&gt;          ]
1&gt;          C:\Users\Bla\Documents\Visual Studio 2010\Projects\boost_1_43_0\boost/thread/detail/thread.hpp(129) : see reference to class template instantiation 'boost::detail::thread_data&lt;F&gt;' being compiled
1&gt;          with
1&gt;          [
1&gt;              F=void (__cdecl myclass::* )(void)
1&gt;          ]
1&gt;          C:\Users\Bla\Documents\Visual Studio 2010\Projects\boost_1_43_0\boost/thread/detail/thread.hpp(160) : see reference to function template instantiation 'boost::detail::thread_data_ptr boost::thread::make_thread_info&lt;F&amp;&gt;(void)' being compiled
1&gt;          with
1&gt;          [
1&gt;              F=void (__cdecl myclass::* )(void)
1&gt;          ]
1&gt;          C:\Users\Bla\Documents\Visual Studio 2010\Projects\boost_1_43_0\boost/thread/detail/thread_group.hpp(39) : see reference to function template instantiation 'boost::thread::thread&lt;F&gt;(F,boost::thread::dummy *)' being compiled
1&gt;          with
1&gt;          [
1&gt;              F=void (__cdecl myclass::* )(void)
1&gt;          ]
1&gt;          main.cpp(148) : see reference to function template instantiation 'boost::thread *boost::thread_group::create_thread&lt;void(__cdecl myclass::* )(void)&gt;(F)' being compiled
1&gt;          with
1&gt;          [
1&gt;              F=void (__cdecl myclass::* )(void)
1&gt;          ]
</code></pre>
<p>(Zeilennummern stimmen nicht)</p>
<p>Das Problem ist, dass die Thread-Funktion eine Memberfunktion meiner Klasse ist. Wie kann ich das lösen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1937267</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1937267</guid><dc:creator><![CDATA[dsfdsfsfd]]></dc:creator><pubDate>Fri, 06 Aug 2010 19:53:41 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit boost::thread on Fri, 06 Aug 2010 19:56:29 GMT]]></title><description><![CDATA[<p>boost::bind</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1937268</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1937268</guid><dc:creator><![CDATA[l&#x27;abra d&#x27;or]]></dc:creator><pubDate>Fri, 06 Aug 2010 19:56:29 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit boost::thread on Fri, 06 Aug 2010 20:00:11 GMT]]></title><description><![CDATA[<p>Danke! und wie genau damit?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1937270</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1937270</guid><dc:creator><![CDATA[dsdffsdf]]></dc:creator><pubDate>Fri, 06 Aug 2010 20:00:11 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit boost::thread on Fri, 06 Aug 2010 20:13:34 GMT]]></title><description><![CDATA[<p>dsdffsdf schrieb:</p>
<blockquote>
<p>Danke! und wie genau damit?</p>
</blockquote>
<p>Es sind mittlerweile 13 Minuten vergangen und du hast immer noch nicht nach &quot;boost::thread mit boost::bind&quot; gegoogelt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1937274</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1937274</guid><dc:creator><![CDATA[l&#x27;abra d&#x27;or]]></dc:creator><pubDate>Fri, 06 Aug 2010 20:13:34 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit boost::thread on Fri, 06 Aug 2010 20:16:57 GMT]]></title><description><![CDATA[<p>Danke, ich hatte nur nach boost::bind gesucht!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1937275</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1937275</guid><dc:creator><![CDATA[dfgfdg]]></dc:creator><pubDate>Fri, 06 Aug 2010 20:16:57 GMT</pubDate></item></channel></rss>