<?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[Thread-Save Datenverwaltung]]></title><description><![CDATA[<p>Hi,<br />
also gleich zu Anfang, ich weiß das es Boost gibt und viele andere libs die das sehr gut können, aber ich würde gerne lernen was dahinter steckt und zu Übungszwecken mal so etwas selber implemieren.</p>
<p>Gut, nun zum eigentlichen...<br />
Ich möchte eine Klasse aufbauen die Daten (Variablen types) thread sicher verwaltet und gleichzeitig maximale Geschwindigkeit hat.</p>
<p>Mein jetziger Ansatz war über Mutex und sieht wie folgt aus:</p>
<pre><code class="language-cpp">template&lt;class T&gt;
class ThreadSaveData
{
private:
    T* m_data;
    HANDLE m_mutex;

public:

    ThreadSaveData&lt;T&gt;(T p_data);
    ~ThreadSaveData&lt;T&gt;(void);

    void setData(T p_data, unsigned int p_timeout = 5000);    
    T getData(unsigned int p_timeout = 5000);
};
</code></pre>
<pre><code class="language-cpp">template &lt;class T&gt;
ThreadSaveData&lt;T&gt;::ThreadSaveData(T p_data)
{
	m_data = new T;
	m_mutex = CreateMutex(NULL,true,this);

	if(!m_mutex)
	{
		throw(0);
	}
	else
	{
		ReleaseMutex(m_mutex);
	}
}

template &lt;class T&gt;
ThreadSaveData&lt;T&gt;::~ThreadSaveData(void)
{
	if(WaitForSingleObject(m_mutex, INFINITE)==WAIT_TIMEOUT) 
	{
		std::cout&lt;&lt;&quot;Mutex kann nicht freigegeben werden&quot;&lt;&lt;std::endl;
		Sleep(2000);
		throw(0);//exit(1);
	}
	else
	{
		delete m_data;
		CloseHandle(m_mutex);
	}
}

template &lt;class T&gt;
void ThreadSaveData&lt;T&gt;::setData(T p_data, unsigned int p_timeout)
{
	if(WaitForSingleObject(m_mutex, p_timeout)==WAIT_TIMEOUT) 
	{
		std::cout&lt;&lt;&quot;Mutex kann nicht freigegeben werden&quot;&lt;&lt;std::endl;
		Sleep(2000);
		throw(0);//exit(1);
	}
	else
	{
		*m_data = p_data;
		ReleaseMutex(m_mutex);
	}
}

template &lt;class T&gt;
T ThreadSaveData&lt;T&gt;::getData(unsigned int p_timeout)
{
	if(WaitForSingleObject(m_mutex, p_timeout)==WAIT_TIMEOUT) 
	{
		std::cout&lt;&lt;&quot;Mutex kann nicht freigegeben werden&quot;&lt;&lt;std::endl;
		Sleep(2000);
		throw(0);//exit(1);
	}
	else
	{
		T p_data = *m_data;
		ReleaseMutex(m_mutex);
		return p_data;
	}
}
</code></pre>
<p>Soweit so gut, mir wurde aber jetzt gesagt das diese Möglichkeit alles andere als schnell sein soll.<br />
Stattdessen wurde mir zu einer Kombination aus einem im Hintergrund laufenden Verwaltungsthread und Events geraten, dies soll mehrkern optimierter sein.</p>
<p>Könnt ihr dazu was sagen? Ich habe keine Ahnung wie ich die Daten aus einem Verwaltungsthread zum aufrufenden Thread bekommen soll...</p>
<p>Mfg. Matyr</p>
<p>Edit: angemerkte Fehler wurden geändert bzw. markiert</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/274261/thread-save-datenverwaltung</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 06:22:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/274261.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 22 Sep 2010 15:55:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Wed, 22 Sep 2010 16:27:51 GMT]]></title><description><![CDATA[<p>Hi,<br />
also gleich zu Anfang, ich weiß das es Boost gibt und viele andere libs die das sehr gut können, aber ich würde gerne lernen was dahinter steckt und zu Übungszwecken mal so etwas selber implemieren.</p>
<p>Gut, nun zum eigentlichen...<br />
Ich möchte eine Klasse aufbauen die Daten (Variablen types) thread sicher verwaltet und gleichzeitig maximale Geschwindigkeit hat.</p>
<p>Mein jetziger Ansatz war über Mutex und sieht wie folgt aus:</p>
<pre><code class="language-cpp">template&lt;class T&gt;
class ThreadSaveData
{
private:
    T* m_data;
    HANDLE m_mutex;

public:

    ThreadSaveData&lt;T&gt;(T p_data);
    ~ThreadSaveData&lt;T&gt;(void);

    void setData(T p_data, unsigned int p_timeout = 5000);    
    T getData(unsigned int p_timeout = 5000);
};
</code></pre>
<pre><code class="language-cpp">template &lt;class T&gt;
ThreadSaveData&lt;T&gt;::ThreadSaveData(T p_data)
{
	m_data = new T;
	m_mutex = CreateMutex(NULL,true,this);

	if(!m_mutex)
	{
		throw(0);
	}
	else
	{
		ReleaseMutex(m_mutex);
	}
}

template &lt;class T&gt;
ThreadSaveData&lt;T&gt;::~ThreadSaveData(void)
{
	if(WaitForSingleObject(m_mutex, INFINITE)==WAIT_TIMEOUT) 
	{
		std::cout&lt;&lt;&quot;Mutex kann nicht freigegeben werden&quot;&lt;&lt;std::endl;
		Sleep(2000);
		throw(0);//exit(1);
	}
	else
	{
		delete m_data;
		CloseHandle(m_mutex);
	}
}

template &lt;class T&gt;
void ThreadSaveData&lt;T&gt;::setData(T p_data, unsigned int p_timeout)
{
	if(WaitForSingleObject(m_mutex, p_timeout)==WAIT_TIMEOUT) 
	{
		std::cout&lt;&lt;&quot;Mutex kann nicht freigegeben werden&quot;&lt;&lt;std::endl;
		Sleep(2000);
		throw(0);//exit(1);
	}
	else
	{
		*m_data = p_data;
		ReleaseMutex(m_mutex);
	}
}

template &lt;class T&gt;
T ThreadSaveData&lt;T&gt;::getData(unsigned int p_timeout)
{
	if(WaitForSingleObject(m_mutex, p_timeout)==WAIT_TIMEOUT) 
	{
		std::cout&lt;&lt;&quot;Mutex kann nicht freigegeben werden&quot;&lt;&lt;std::endl;
		Sleep(2000);
		throw(0);//exit(1);
	}
	else
	{
		T p_data = *m_data;
		ReleaseMutex(m_mutex);
		return p_data;
	}
}
</code></pre>
<p>Soweit so gut, mir wurde aber jetzt gesagt das diese Möglichkeit alles andere als schnell sein soll.<br />
Stattdessen wurde mir zu einer Kombination aus einem im Hintergrund laufenden Verwaltungsthread und Events geraten, dies soll mehrkern optimierter sein.</p>
<p>Könnt ihr dazu was sagen? Ich habe keine Ahnung wie ich die Daten aus einem Verwaltungsthread zum aufrufenden Thread bekommen soll...</p>
<p>Mfg. Matyr</p>
<p>Edit: angemerkte Fehler wurden geändert bzw. markiert</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956029</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956029</guid><dc:creator><![CDATA[Matyr]]></dc:creator><pubDate>Wed, 22 Sep 2010 16:27:51 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Wed, 22 Sep 2010 16:02:43 GMT]]></title><description><![CDATA[<p>Du hast keine CreateMutex, OpenMutex,... Aufrufe in deinem Code...</p>
<p><a href="http://www.relisoft.com/win32/active.html" rel="nofollow">http://www.relisoft.com/win32/active.html</a> / <a href="http://msdn.microsoft.com/en-us/library/ms686927(v=VS.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms686927(v=VS.85).aspx</a></p>
<p>Prinzipiell spricht aber erstmal nichts dagegen hier einen Mutex zu verwenden. Erstmal richtig machen, und dann schnell.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956034</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956034</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Wed, 22 Sep 2010 16:02:43 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Wed, 22 Sep 2010 16:09:47 GMT]]></title><description><![CDATA[<p>Hab ich schon im C'tor, habe den nur nicht gepostet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956042</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956042</guid><dc:creator><![CDATA[Matyr]]></dc:creator><pubDate>Wed, 22 Sep 2010 16:09:47 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Wed, 22 Sep 2010 16:20:05 GMT]]></title><description><![CDATA[<p>exit(..) in C++ ist typischerweise keine gute Idee. Es werden keine Destruktoren aufgerufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956045</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956045</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Wed, 22 Sep 2010 16:20:05 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Wed, 22 Sep 2010 16:22:26 GMT]]></title><description><![CDATA[<p>Ok, werde ich durch throw() ersetzen bis mir was Besseres einfällt.</p>
<p>Aber wenn es eh eine effektivere Möglichkeit für die ganze Verwaltung gibt verschindet das Problem ja eh.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956046</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956046</guid><dc:creator><![CDATA[Matyr]]></dc:creator><pubDate>Wed, 22 Sep 2010 16:22:26 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Wed, 22 Sep 2010 19:36:06 GMT]]></title><description><![CDATA[<p>theta schrieb:</p>
<blockquote>
<p>exit(..) in C++ ist typischerweise keine gute Idee. Es werden keine Destruktoren aufgerufen.</p>
</blockquote>
<p>Quelle bitte</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956141</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956141</guid><dc:creator><![CDATA[Wirklich?]]></dc:creator><pubDate>Wed, 22 Sep 2010 19:36:06 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Wed, 22 Sep 2010 21:23:16 GMT]]></title><description><![CDATA[<p>ISO/IEC 14882:2003, 18.3 Start and Termination, Absatz 8 schrieb:</p>
<blockquote>
<p>The function exit()has additional behavior in this International Standard:<br />
— First, objects with static storage duration are destroyed and functions registered by calling atexit are called. Non-local objects with static storage duration are destroyed in the reverse order of the completion of their constructor. <strong>(Automatic objects are not destroyed as a result of calling exit().)<sup>207)</sup></strong> Functions registered with atexit are called in the reverse order of their registration, except that a function is called after any previously registered functions that had already been called at the time it was registered.<sup>208)</sup> A function registered with atexit before a non-local object obj1 of static storage duration is initialized will not be called until obj1’s destruction has completed. A function registered with atexit after a non-local object obj2 of static storage duration is initialized will be called before obj2’s destruction starts. A local static object obj3 is destroyed at the same time it would be if a function calling the obj3 destructor were registered with atexit at the completion of the obj3 constructor.<br />
— Next, all open C streams (as mediated by the function signatures declared in &lt;cstdio&gt;) with unwritten buffered data are flushed, all open C streams are closed, and all files created by calling tmpfile() are removed.<sup>209)</sup><br />
— Finally, control is returned to the host environment. If status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned. If status is EXIT_FAILURE, an implementation-defined form of the status unsuccessful termination is returned. Otherwise the status returned is implementation-defined.<sup>210)</sup></p>
<p><sup>207)</sup> Objects with automatic storage duration are all destroyed in a program whose function main() contains no automatic objects<br />
and executes the call to exit(). Control can be transferred directly to such a main() by throwing an exception that is caught in<br />
main().<br />
<sup>208)</sup> A function is called for every time it is registered.<br />
<sup>209)</sup> Any C streams associated with cin, cout, etc (27.3) are flushed and closed when static objects are destroyed in the previous<br />
phase. The function tmpfile()is declared in &lt;cstdio&gt;.<br />
<sup>210)</sup> The macros EXIT_FAILUREand EXIT_SUCCESSare defined in &lt;cstdlib&gt;.</p>
</blockquote>
<p>Reicht dies als Quelle? <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>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956206</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956206</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Wed, 22 Sep 2010 21:23:16 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Thu, 23 Sep 2010 12:06:46 GMT]]></title><description><![CDATA[<p>Gut, hab das geändert aber leider hilft mir das bei der Geschwindigkeitsoptimierung nicht viel weiter.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956408</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956408</guid><dc:creator><![CDATA[Matyr]]></dc:creator><pubDate>Thu, 23 Sep 2010 12:06:46 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Thu, 23 Sep 2010 12:08:53 GMT]]></title><description><![CDATA[<p>Für bessere Performance benutze Critical Sections, das sind keine Kernel Objekte.<br />
Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956410</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956410</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Thu, 23 Sep 2010 12:08:53 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Thu, 23 Sep 2010 12:21:41 GMT]]></title><description><![CDATA[<p>Habe gerade diesen Beitrag hier gefunden: <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-271570.html" rel="nofollow">Link</a></p>
<p>Da wird ja relativ genau auf CS und Interlock (was immer das auch ist) eingegangen.</p>
<p>Die Frage bleibt, ist es effektiver das ganze irgendwie über Events und einem Daten-Verwaltungs-Thread zu machen oder so wie es jetzt ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956425</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956425</guid><dc:creator><![CDATA[Matyr]]></dc:creator><pubDate>Thu, 23 Sep 2010 12:21:41 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Thu, 23 Sep 2010 15:50:54 GMT]]></title><description><![CDATA[<p>Matyr schrieb:</p>
<blockquote>
<p>Die Frage bleibt, ist es effektiver das ganze irgendwie über Events und einem Daten-Verwaltungs-Thread zu machen oder so wie es jetzt ist.</p>
</blockquote>
<p>Unterschiedliche Anforderungen bringen unterschiedliche Ergebnisse.</p>
<p>Prinzipiell ist dein Ansatz passend.</p>
<p>Wenn du zB in ThreadSaveData nur primitive Typen hältst ist ein InterlockedExchange() wahrscheinlich das schnellste. Das Stichwort hier wäre CAS (compare and set/swap).</p>
<p>Crtitcal Sections sind nicht über mehrere Prozesse Hinweg benutzbar dafür idR einen Tick schneller als Mutexes.</p>
<p>Die Performance spielt aber nur dann eine Rolle wenn du oft für kurze Zeit lockst. Wenn du selten für lange Zeit lockst ist es komplett egal.</p>
<p>Das mit den Events und Verwaltungsthread verstehe ich nicht. Kannst du erklären was da gemeint ist?</p>
<p>Und: Was ist das Anforderungsprofil?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956531</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956531</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Thu, 23 Sep 2010 15:50:54 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Thu, 23 Sep 2010 16:28:15 GMT]]></title><description><![CDATA[<p>Die Anforderungen sind sehr kurze locks in denen meist nur kleine Datenmengen gelesen oder geschrieben werden. In der Regel &gt;=20Byte.<br />
Ganz selten auch mehr,in etwa 1kb.<br />
Gelockt soll wenn es performance technisch geht etwa 20 - 40mal in der Sekunde werden.</p>
<p>Das was ich mit Verwaltungsthread meine ist ein SON (service orientatet network oder so) system.</p>
<p>Daher ein Thread auf den man mit events zugreift und der den anderen Threads bescheid gibt das Daten belegt werden. (Wenn ich das richtig verstanden habe)<br />
Dadurch soll eine höhere Geschwindigkeit gewährleistet sein und vor allem viel Dynamischer.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956540</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956540</guid><dc:creator><![CDATA[Matyr]]></dc:creator><pubDate>Thu, 23 Sep 2010 16:28:15 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Fri, 24 Sep 2010 12:27:50 GMT]]></title><description><![CDATA[<p>Muss man eigentlich bei Lesezugriff ein Mutex bzw. CS überhaupt setzen?<br />
Oder reicht es wenn nur abgefragt wird ob irgendwo Schreibzugriff ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956875</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956875</guid><dc:creator><![CDATA[Matyr]]></dc:creator><pubDate>Fri, 24 Sep 2010 12:27:50 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Fri, 24 Sep 2010 12:36:16 GMT]]></title><description><![CDATA[<p>wenn du nur liest, ist das ok<br />
wenn du allerdings iwo schreibst und gleichzeitig in nem anderen thread liest, kann es sein, dass du müll liest</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956880</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956880</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Fri, 24 Sep 2010 12:36:16 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Fri, 24 Sep 2010 12:41:32 GMT]]></title><description><![CDATA[<p>Deswegen wird beim Schreiben der Mutex gesetzt, in der lese Funktion wird einfach nur geprüft ob er gesetzt wurde, wenn ja wartet er, wenn nicht wird einfach gelesen.</p>
<p>Problem ist vielleicht nur das wenn das lesen länger als ein Takt dauert und dann etwas Anfängt zu schreiben...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956882</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956882</guid><dc:creator><![CDATA[Matyr]]></dc:creator><pubDate>Fri, 24 Sep 2010 12:41:32 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Fri, 24 Sep 2010 13:16:54 GMT]]></title><description><![CDATA[<p>Matyr schrieb:</p>
<blockquote>
<p>Deswegen wird beim Schreiben der Mutex gesetzt, in der lese Funktion wird einfach nur geprüft ob er gesetzt wurde, wenn ja wartet er, wenn nicht wird einfach gelesen.</p>
<p>Problem ist vielleicht nur das wenn das lesen länger als ein Takt dauert und dann etwas Anfängt zu schreiben...</p>
</blockquote>
<p>richtig - deshalb schrieb ich ja, dass es schief geht, wenn ein thread gerade schreibt und der andere liest... (bzw schief gehen kann - nicht muss)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1956901</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1956901</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Fri, 24 Sep 2010 13:16:54 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Tue, 28 Sep 2010 12:58:23 GMT]]></title><description><![CDATA[<p>So habe dass nun mit CriticalSection implemiert,<br />
zusätzlich habe ich eine eigene CS programmiert (naja mit Anleitung von CodeProject) die schneller sein soll.</p>
<p>Nun ist die Frage wie ich die Geschwindigkeiten der beiden mal messen bzw. vergleichen kann. Die Zeit zu messen wird denke ich zu ungenau. Effektiv ist wahrscheinlich ein vergleich der Rechenschritte,<br />
nur weiß ich leider nicht wie das effektiv geht.</p>
<p>Ist clock(); ein vernünftiger Ansatz?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1958512</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1958512</guid><dc:creator><![CDATA[Matyr]]></dc:creator><pubDate>Tue, 28 Sep 2010 12:58:23 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Tue, 28 Sep 2010 18:23:14 GMT]]></title><description><![CDATA[<p>Matyr schrieb:</p>
<blockquote>
<p>Ist clock(); ein vernünftiger Ansatz?</p>
</blockquote>
<p>Nö, dafür eignet sich eher QueryPerformanceCounter() (siehe MSDN).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1958673</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1958673</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 28 Sep 2010 18:23:14 GMT</pubDate></item><item><title><![CDATA[Reply to Thread-Save Datenverwaltung on Wed, 06 Oct 2010 20:42:12 GMT]]></title><description><![CDATA[<p>So meine CS ist fertig und durchgemessen.</p>
<p>Zeit normalle CS: 3400<br />
Zeit meine CS: 2000</p>
<p>Kann aber wegen Optimierung des Compilers vielleicht falsch sein.<br />
Initialisieren ist etwas langsamer, schätzungweise 5-10% was aber anhand der anderen Ergebnisse verkraftbar ist.</p>
<p>Mfg. Matyr</p>
<p>Folgendes Messverfahren:</p>
<pre><code>QueryPerformanceCounter((LARGE_INTEGER*)&amp;count1);
    for(int i=0;i&lt;30000;i++)
    {
        EnterCriticalSection(&amp;cs);    
        LeaveCriticalSection(&amp;cs);    
    }
    QueryPerformanceCounter((LARGE_INTEGER*)&amp;count2);
    cout&lt;&lt;&quot;Enter/Leave CS: &quot;&lt;&lt;(count2-count1)&lt;&lt;endl;

    Sleep(50);

    QueryPerformanceCounter((LARGE_INTEGER*)&amp;count1);
    for(int i=0;i&lt;30000;i++)
    {
        myCs.Lock();    
        myCs.Unlock();
    }
    QueryPerformanceCounter((LARGE_INTEGER*)&amp;count2);
    cout&lt;&lt;&quot;Enter/Leave MyCS: &quot;&lt;&lt;(count2-count1)&lt;&lt;endl;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1962323</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1962323</guid><dc:creator><![CDATA[Matyr]]></dc:creator><pubDate>Wed, 06 Oct 2010 20:42:12 GMT</pubDate></item></channel></rss>