<?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[100% cpu]]></title><description><![CDATA[<p>hi<br />
wenn ich mit blocking sockets arbeite habe ich einen thread der recv in einer while schleife aufruft also so</p>
<pre><code>VOID ReceiveThread( PVOID pvoid )
{ 
        char buffer[4096];
	    MMD *pObj = (MMD*)pvoid;
	      while(1) {
		        unsigned nRet = recv( pObj-&gt;m_socket, buffer, 4096, 0 );

//etc
        }

}
</code></pre>
<p>und damit habe ich immer 100 cpu auslastung, wie muss man das richtig machen wenn man blcoking sockets und multithreading verwendet. also ich weiss das man asynchrone sockets machen kann, aber wenn ich es so mache wie da oben, was mache ich da falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/121140/100-cpu</link><generator>RSS for Node</generator><lastBuildDate>Sun, 05 Jul 2026 16:09:17 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/121140.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 20 Sep 2005 11:12:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to 100% cpu on Tue, 20 Sep 2005 11:12:53 GMT]]></title><description><![CDATA[<p>hi<br />
wenn ich mit blocking sockets arbeite habe ich einen thread der recv in einer while schleife aufruft also so</p>
<pre><code>VOID ReceiveThread( PVOID pvoid )
{ 
        char buffer[4096];
	    MMD *pObj = (MMD*)pvoid;
	      while(1) {
		        unsigned nRet = recv( pObj-&gt;m_socket, buffer, 4096, 0 );

//etc
        }

}
</code></pre>
<p>und damit habe ich immer 100 cpu auslastung, wie muss man das richtig machen wenn man blcoking sockets und multithreading verwendet. also ich weiss das man asynchrone sockets machen kann, aber wenn ich es so mache wie da oben, was mache ich da falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/876470</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/876470</guid><dc:creator><![CDATA[k1]]></dc:creator><pubDate>Tue, 20 Sep 2005 11:12:53 GMT</pubDate></item><item><title><![CDATA[Reply to 100% cpu on Tue, 20 Sep 2005 11:16:32 GMT]]></title><description><![CDATA[<p>Der Fehler liegt woanders oder recv schlägt immer sofort fehl.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/876475</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/876475</guid><dc:creator><![CDATA[100%]]></dc:creator><pubDate>Tue, 20 Sep 2005 11:16:32 GMT</pubDate></item><item><title><![CDATA[Reply to 100% cpu on Tue, 20 Sep 2005 11:17:34 GMT]]></title><description><![CDATA[<p>mach erstmal</p>
<pre><code class="language-cpp">Sleep(10);
</code></pre>
<p>in die schleife rein. dann haste nichtmehr 100%.<br />
das ist aber nur ne notlösung und die frage bleibt bestehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/876479</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/876479</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 20 Sep 2005 11:17:34 GMT</pubDate></item><item><title><![CDATA[Reply to 100% cpu on Tue, 20 Sep 2005 20:54:31 GMT]]></title><description><![CDATA[<p>hi,<br />
also der fehler scheint wirklich nicht in diesem recv thread zu sein...ich hab noch einen thread zum senden, der soll immer gucken ob was in einem buffer ist und wenn ja es absenden mit send und ansonsten sollte er die Kontrolle weitergeben, das habe ich so versucht :</p>
<pre><code class="language-cpp">while(1)
	{
		if( pObj-&gt;m_out.empty() ) {
			Sleep(0);
			continue;
		}

			unsigned nRet = send( pObj-&gt;m_socket, pObj-&gt;m_out.front().c_str(),
								  pObj-&gt;m_out.front().length(), 0 );

			pObj-&gt;m_out.pop_front();
	}
</code></pre>
<p>Aber damit habe ich trotzdem 100% auslastung, wenn ich statt Sleep(0) das Sleep(10) von Volkard versuche, scheint es zu gehen? Wieso geht es mit Sleep(0) denn nicht? In der msdn steht dazu :</p>
<p>A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/876658</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/876658</guid><dc:creator><![CDATA[k1]]></dc:creator><pubDate>Tue, 20 Sep 2005 20:54:31 GMT</pubDate></item><item><title><![CDATA[Reply to 100% cpu on Tue, 20 Sep 2005 21:30:54 GMT]]></title><description><![CDATA[<p>Checkst du auch die Rückgabewerte von send/recv?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/876678</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/876678</guid><dc:creator><![CDATA[f1]]></dc:creator><pubDate>Tue, 20 Sep 2005 21:30:54 GMT</pubDate></item><item><title><![CDATA[Reply to 100% cpu on Tue, 20 Sep 2005 21:48:49 GMT]]></title><description><![CDATA[<p>k1 schrieb:</p>
<blockquote>
<p>A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run.</p>
</blockquote>
<p>ein wert von null verursacht den thread, den rest seiner zeitscheibe preiszugeben zugusten für irgendeinen anderen thread gleicher priorität, der bereit zum laufen ist.<br />
(nicht schön, aber recht wörtlich).<br />
wenn kein anderer wartet, macht deiner einfach weiter. der trick mit Sleep(10) ist, daß du *nur* ca. 100-mal pro sekunde durch die schleife läufst. da langweilt sich der rechner zu tode.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/876688</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/876688</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 20 Sep 2005 21:48:49 GMT</pubDate></item><item><title><![CDATA[Reply to 100% cpu on Wed, 21 Sep 2005 06:48:57 GMT]]></title><description><![CDATA[<p>Hi</p>
<p>Ich verstehe das nicht ganz was du damit meinst?????</p>
<p>kannste dich auch ein wenig deutlicher ausdrücken????</p>
]]></description><link>https://www.c-plusplus.net/forum/post/876709</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/876709</guid><dc:creator><![CDATA[Fipse]]></dc:creator><pubDate>Wed, 21 Sep 2005 06:48:57 GMT</pubDate></item></channel></rss>