<?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[Sleep Funktion erstellen]]></title><description><![CDATA[<p>Abend miteinander,<br />
ich muss zu Mittwoch für die Schule eine Sleep Funktion erstellen die denn Computer für x Sekunden schlafen lässt, ich darf aber keine Zeit Bibliothek (z.B. time.h) verwenden oder andere Sleep Funktionen. Nur leider verstehe ich nicht richtig wie ich das hinkriegen soll, ich habe mich erkundigt und jetzt herausgefunden das man das wohl mit der CPU (Takt/Taktfrequenz) machen kann.<br />
Doch irgendwie verstehe ich denn Sinn dahinter nicht und auch nicht wie man das hinkriegen soll, kann mir wer helfen?</p>
<p>Bis dann<br />
MobUo</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/327045/sleep-funktion-erstellen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 09 Jul 2026 21:28:01 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/327045.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 20 Jul 2014 19:56:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Sleep Funktion erstellen on Sun, 20 Jul 2014 19:56:23 GMT]]></title><description><![CDATA[<p>Abend miteinander,<br />
ich muss zu Mittwoch für die Schule eine Sleep Funktion erstellen die denn Computer für x Sekunden schlafen lässt, ich darf aber keine Zeit Bibliothek (z.B. time.h) verwenden oder andere Sleep Funktionen. Nur leider verstehe ich nicht richtig wie ich das hinkriegen soll, ich habe mich erkundigt und jetzt herausgefunden das man das wohl mit der CPU (Takt/Taktfrequenz) machen kann.<br />
Doch irgendwie verstehe ich denn Sinn dahinter nicht und auch nicht wie man das hinkriegen soll, kann mir wer helfen?</p>
<p>Bis dann<br />
MobUo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2409605</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409605</guid><dc:creator><![CDATA[MobUo]]></dc:creator><pubDate>Sun, 20 Jul 2014 19:56:23 GMT</pubDate></item><item><title><![CDATA[Reply to Sleep Funktion erstellen on Sun, 20 Jul 2014 20:07:06 GMT]]></title><description><![CDATA[<p>Nun, mit Standard-C++ hat das dann nichts zu tun.</p>
<p>Außer wir spielen kurz den Krümelkacker und nutzen<a href="http://en.cppreference.com/w/cpp/thread/sleep_for" rel="nofollow"> <code>std::this_thread::sleep_for</code> </a>- ist nämlich Teil einer Threading-Bibliothek. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2409607</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409607</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 20 Jul 2014 20:07:06 GMT</pubDate></item><item><title><![CDATA[Reply to Sleep Funktion erstellen on Sun, 20 Jul 2014 20:07:37 GMT]]></title><description><![CDATA[<p>Theoretisch könntest du, wenn weisst, wie viele Taktzyklen deine CPU pro Sekunden machen kann, entsprechend viele Operationen ausführen lassen. Z.B. kann deine CPU pro Sekunde 3Mrd. Operationen ausführen. Für 5 Sekudnen machst halt 15 Mrd. Operationen.</p>
<p>In der Praxis wird das aber nicht klappen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2409608</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409608</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Sun, 20 Jul 2014 20:07:37 GMT</pubDate></item><item><title><![CDATA[Reply to Sleep Funktion erstellen on Sun, 20 Jul 2014 20:19:41 GMT]]></title><description><![CDATA[<p>Obwohl ist das nicht auch mit for Schleifen möglich?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2409614</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409614</guid><dc:creator><![CDATA[MobUo]]></dc:creator><pubDate>Sun, 20 Jul 2014 20:19:41 GMT</pubDate></item><item><title><![CDATA[Reply to Sleep Funktion erstellen on Sun, 20 Jul 2014 20:36:01 GMT]]></title><description><![CDATA[<p>MobUo schrieb:</p>
<blockquote>
<p>Obwohl ist das nicht auch mit for Schleifen möglich?</p>
</blockquote>
<p>Ja und nein.<br />
Der Compiler optimiert leere for-Schleifen auch gerne mal einfach weg.</p>
<pre><code>for(int i=0;i&lt;1000000;++i){
}
</code></pre>
<p>könnte er ganz wegmachen.</p>
<p>Bisher ein sicheres Mittel dagegen ist</p>
<pre><code>for(int i=0;i&lt;1000000;++i){
   cout&lt;&lt;&quot;&quot;;
}
</code></pre>
<p>Aber dann haste keine Kontrolle mehr über die Takte.</p>
<p>Hoffe, es reicht, wenn Du den Rechner vorher einfach ausmisst. Also mal bis 1000000 laufen lassen und wenn er dafür 15s braucht, rechnest Du 1000000/15 und hast ne Zeitschleife, die ungefähr eine Sekunde braucht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2409619</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409619</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 20 Jul 2014 20:36:01 GMT</pubDate></item><item><title><![CDATA[Reply to Sleep Funktion erstellen on Sun, 20 Jul 2014 20:39:32 GMT]]></title><description><![CDATA[<p>Also müsste man eigentlich nur nebenbei einen Timer laufen lassen und dann 1000000 durch den Timer teilen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2409621</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409621</guid><dc:creator><![CDATA[MobUo]]></dc:creator><pubDate>Sun, 20 Jul 2014 20:39:32 GMT</pubDate></item><item><title><![CDATA[Reply to Sleep Funktion erstellen on Sun, 20 Jul 2014 21:00:35 GMT]]></title><description><![CDATA[<p>Wenn du nen Timer zur Verfügung hast, kannst du den doch gleich für das Sleep benutzen. Ich dachte der Clou wäre, das ganze ohne Timer-Bibliothek zu machen.</p>
<p>Aber mal kurz die Möglichkeiten zusammengefasst:<br />
Es geht nicht.<br />
Und wenn es doch geht, dann nicht ansatzweise portabel.<br />
Und wenn man das hinkriegt, ist es nicht sinnvoll, weil das hochjagen der CPU-Last durch das milliardenfache Abprüfen einer Schleifenbedingung ungefähr das Gegenteil von Schlafen ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2409622</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409622</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Sun, 20 Jul 2014 21:00:35 GMT</pubDate></item><item><title><![CDATA[Reply to Sleep Funktion erstellen on Sun, 20 Jul 2014 21:06:11 GMT]]></title><description><![CDATA[<p>Ist mir auch aufgefallen für einen Timer brauch man ja Sekunden ... Was ist eigentlich dir/der/das QueryPerformanceFrequency?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2409624</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409624</guid><dc:creator><![CDATA[MobUo]]></dc:creator><pubDate>Sun, 20 Jul 2014 21:06:11 GMT</pubDate></item><item><title><![CDATA[Reply to Sleep Funktion erstellen on Sun, 20 Jul 2014 21:14:36 GMT]]></title><description><![CDATA[<p>MobUo schrieb:</p>
<blockquote>
<p>Also müsste man eigentlich nur nebenbei einen Timer laufen lassen und dann 1000000 durch den Timer teilen</p>
</blockquote>
<p>Dachte, Du schaust zum Zeitmessen auf die Armbanduhr und stellst so fest, wie schnell der Rechner ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2409627</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409627</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 20 Jul 2014 21:14:36 GMT</pubDate></item><item><title><![CDATA[Reply to Sleep Funktion erstellen on Sun, 20 Jul 2014 21:24:00 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/106">@volkard</a><br />
Zu ungenau <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2409630</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409630</guid><dc:creator><![CDATA[MobUo]]></dc:creator><pubDate>Sun, 20 Jul 2014 21:24:00 GMT</pubDate></item><item><title><![CDATA[Reply to Sleep Funktion erstellen on Sun, 20 Jul 2014 22:16:39 GMT]]></title><description><![CDATA[<p>Hier hast du mal die Taktfreuqenz:</p>
<pre><code>#include &lt;NTstatus.h&gt;
#define WIN32_NO_STATUS
#include &lt;windows.h&gt;
#include &lt;Powrprof.h&gt;
#include &lt;iostream&gt;

typedef struct _PROCESSOR_POWER_INFORMATION {
   ULONG  Number;
   ULONG  MaxMhz;
   ULONG  CurrentMhz;
   ULONG  MhzLimit;
   ULONG  MaxIdleState;
   ULONG  CurrentIdleState;
} PROCESSOR_POWER_INFORMATION, *PPROCESSOR_POWER_INFORMATION;

#pragma comment(lib, &quot;Powrprof.lib&quot;)

int main()
{
   // get the number or processors 
   SYSTEM_INFO si = {0};
   ::GetSystemInfo(&amp;si);
   // allocate buffer to get info for each processor
   const int size = si.dwNumberOfProcessors * sizeof(PROCESSOR_POWER_INFORMATION);
   LPBYTE pBuffer = new BYTE[size]; 
   int time = 0;
   std::cin &gt;&gt; time;
   PPROCESSOR_POWER_INFORMATION ppi = (PPROCESSOR_POWER_INFORMATION)pBuffer;
   int hz = (ppi-&gt;CurrentMhz * 1000);
   return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2409632</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409632</guid><dc:creator><![CDATA[vfds&amp;lt;fvfgas]]></dc:creator><pubDate>Sun, 20 Jul 2014 22:16:39 GMT</pubDate></item><item><title><![CDATA[Reply to Sleep Funktion erstellen on Sun, 20 Jul 2014 21:39:57 GMT]]></title><description><![CDATA[<p>Jetzt brauchst du nur noch eine Schleife bei der du genau weißt wie viele Takte pro durchgang gebraucht werden, kannste mit Inline Assembler oder so basteln.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2409633</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409633</guid><dc:creator><![CDATA[trgegvsgfga]]></dc:creator><pubDate>Sun, 20 Jul 2014 21:39:57 GMT</pubDate></item><item><title><![CDATA[Reply to Sleep Funktion erstellen on Sun, 20 Jul 2014 21:43:16 GMT]]></title><description><![CDATA[<p>Oh, sorry, das ist taktfrequenz mal Zeit, kann aber keine Beiträge editieren, tu einfach das &quot;* time&quot; in der klammer weg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2409634</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409634</guid><dc:creator><![CDATA[fafdasfasgag]]></dc:creator><pubDate>Sun, 20 Jul 2014 21:43:16 GMT</pubDate></item><item><title><![CDATA[Reply to Sleep Funktion erstellen on Sun, 20 Jul 2014 21:48:16 GMT]]></title><description><![CDATA[<p>Das ist die &quot;beste&quot; Lösung, die mir einfällt:</p>
<pre><code class="language-cpp">void sleep(unsigned seconds)
{
	if (seconds == 0)
	{
		return;
	}
	if (seconds == 1)
	{
		std::cout &lt;&lt; &quot;Error E5102 occured. Press [Enter] to continue\n&quot;;
	}
	else
	{
		std::cout &lt;&lt; &quot;Press [Enter] &quot; &lt;&lt; (seconds - 1) &lt;&lt; &quot; seconds after you read this message\n&quot;;
	}
	std::string ignored;
	std::getline(std::cin, ignored);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2409635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409635</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Sun, 20 Jul 2014 21:48:16 GMT</pubDate></item><item><title><![CDATA[Reply to Sleep Funktion erstellen on Sun, 20 Jul 2014 22:17:22 GMT]]></title><description><![CDATA[<p>@fafdasfasgag: Korrigiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2409636</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2409636</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 20 Jul 2014 22:17:22 GMT</pubDate></item></channel></rss>