<?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 globale variable oder so aehnlich]]></title><description><![CDATA[<p>hola</p>
<p>gibt es sowas aehnliches wie ne thread globale und thread-static variable ?<br />
oder kann man sich sowas auch irgendwie zusammen basteln ?<br />
das ich pro thread nur einmal eine klasseninstanz erstellen kann, jedoch mehrere im prozess ?<br />
hoffendlich hab ich mich da halb wegs verstaendlich ausgedrueckt</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/111660/thread-globale-variable-oder-so-aehnlich</link><generator>RSS for Node</generator><lastBuildDate>Wed, 01 Jul 2026 04:33:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/111660.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 03 Jun 2005 09:59:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to thread globale variable oder so aehnlich on Fri, 03 Jun 2005 11:42:24 GMT]]></title><description><![CDATA[<p>hola</p>
<p>gibt es sowas aehnliches wie ne thread globale und thread-static variable ?<br />
oder kann man sich sowas auch irgendwie zusammen basteln ?<br />
das ich pro thread nur einmal eine klasseninstanz erstellen kann, jedoch mehrere im prozess ?<br />
hoffendlich hab ich mich da halb wegs verstaendlich ausgedrueckt</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/801636</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/801636</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Fri, 03 Jun 2005 11:42:24 GMT</pubDate></item><item><title><![CDATA[Reply to thread globale variable oder so aehnlich on Fri, 03 Jun 2005 12:45:28 GMT]]></title><description><![CDATA[<p>Evtl. ein Singleton, das als Entscheidungskriterium für die Erstellung einer neuen Instanz die Thread ID verwendet? Nur so als Idee...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/801792</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/801792</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Fri, 03 Jun 2005 12:45:28 GMT</pubDate></item><item><title><![CDATA[Reply to thread globale variable oder so aehnlich on Fri, 03 Jun 2005 13:38:56 GMT]]></title><description><![CDATA[<p>__declspec(thread)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/801841</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/801841</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Fri, 03 Jun 2005 13:38:56 GMT</pubDate></item><item><title><![CDATA[Reply to thread globale variable oder so aehnlich on Sat, 04 Jun 2005 13:36:29 GMT]]></title><description><![CDATA[<p><a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/kmarch/hh/kmarch/k102_8d625992-2e36-464d-a771-629d5f08b398.xml.asp" rel="nofollow">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/kmarch/hh/kmarch/k102_8d625992-2e36-464d-a771-629d5f08b398.xml.asp</a></p>
<p>Hi !!<br />
In der obigen adresse findest du eine Funktion die es dir erlaubt eine variable zu erhöhen ohne dass ees ein anderer Thread zur selben Zeit kann.<br />
Allerdings muss diese Variable in einen speziellen bereich der anwedung geschrieben werden. Wenn du VC verwendest geht das so:</p>
<pre><code>#pragma push()
#pragma comment(linker, &quot;/shared&quot;)
long MyVar = 0;
#pragma pop();

BOOL WINAPI WINMAIN(..)
{
   InterlockedIncrement(&amp;MyVar);

   if (MyVar != 1)
   {
      return FALSE;
   }

   while(Running)
   {
     MsgStuff();
     ExecuteProgram();
   }
   InterlockedDecrement(&amp;MyVar);
   return TRUE;
}
</code></pre>
<p>So kann man zum beispiel auf einfache Art und Weise seine anwendung<br />
zwingen nur einmal zu starten !<br />
rya.<br />
Scorcher24</p>
]]></description><link>https://www.c-plusplus.net/forum/post/802151</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/802151</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Sat, 04 Jun 2005 13:36:29 GMT</pubDate></item><item><title><![CDATA[Reply to thread globale variable oder so aehnlich on Sat, 04 Jun 2005 13:37:39 GMT]]></title><description><![CDATA[<p>re</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/2803">@MFK</a>:<br />
kannst du mir das etwas genaeuer erklaeren, wie das funktioniert ?</p>
<p>ich zeig mal ein kurzes beispiel was ich da genau machen will:</p>
<pre><code class="language-cpp">class myclass
{
   ...
   static another_class var; // (1)
   ...
}
</code></pre>
<p>hier hab ich ne klasse, in der ich eine andere klasse verwende, die static deklariert ist. in diesem fall gibt es sie in egal wie vielen myclasses nur einmal. klar. nun moechte ich es so haben, das wenn in einem neuen thread eine myclass benuetzt wird, wieder eine neue instanz von another_class erstelt wird. also pro thread eine instanz von another_class.<br />
funktioniert das nun so mit __declspec(thread) ? wenn ja, koenntest du mir da ein kleines beispiel zeigen ?</p>
<p>cermy</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/802152</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/802152</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Sat, 04 Jun 2005 13:37:39 GMT</pubDate></item><item><title><![CDATA[Reply to thread globale variable oder so aehnlich on Sat, 04 Jun 2005 14:34:10 GMT]]></title><description><![CDATA[<p>Meep Meep schrieb:</p>
<blockquote>
<p>funktioniert das nun so mit __declspec(thread) ?</p>
</blockquote>
<p>Kommt drauf an, was another_class ist.</p>
<p>Hier stehen ein paar Einschränkungen:<br />
<a href="http://msdn.microsoft.com/library/en-us/vclang/html/_pluslang_the_thread_attribute.asp" rel="nofollow">http://msdn.microsoft.com/library/en-us/vclang/html/_pluslang_the_thread_attribute.asp</a></p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;process.h&gt;
#include &lt;iostream&gt;
using namespace std;

class myclass
{
	__declspec(thread) static int i;
public:
	myclass()
	{
		++i;
		cout &lt;&lt; i;
	}
};

__declspec(thread) int myclass::i = 0;

unsigned int __stdcall thread(void* p)
{
	myclass x;
	return 0;
}

int main()
{
	for(int i=0; i&lt;10; ++i)
	{
		_beginthreadex(0, 0, thread, 0, 0, 0);
	}
	Sleep(1000);
}
</code></pre>
<p>...ergibt 1111111111, ohne __declspec(thread) 12345678910.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/802176</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/802176</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Sat, 04 Jun 2005 14:34:10 GMT</pubDate></item><item><title><![CDATA[Reply to thread globale variable oder so aehnlich on Sat, 04 Jun 2005 14:39:42 GMT]]></title><description><![CDATA[<p><a href="http://boost.org/doc/html/thread_specific_ptr.html" rel="nofollow">boost::thead_specific_ptr</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/802178</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/802178</guid><dc:creator><![CDATA[peterchen]]></dc:creator><pubDate>Sat, 04 Jun 2005 14:39:42 GMT</pubDate></item><item><title><![CDATA[Reply to thread globale variable oder so aehnlich on Sat, 04 Jun 2005 15:09:35 GMT]]></title><description><![CDATA[<p>danke euch mal. werd das zeugs jetz mal durch nehmen</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/802189</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/802189</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Sat, 04 Jun 2005 15:09:35 GMT</pubDate></item><item><title><![CDATA[Reply to thread globale variable oder so aehnlich on Sat, 04 Jun 2005 16:15:11 GMT]]></title><description><![CDATA[<p>re</p>
<p>kleines problemchen hab ich nun</p>
<p>hab folgenden code:</p>
<pre><code class="language-cpp">class buffer
{
   public:
      buffer(void) { }
      ~buffer(void) { }
}; /* stark vereinfacht. nur um zu zeigen, das mit ctor nix gemacht werden kann */

class myclass
{
   ...
   public:
      __declspec(thread) static buffer thread_buffer;
      ...
};

__declspec(thread) buffer myclass::thread_buffer(); (1)
</code></pre>
<p>beim kompilieren kommt dann:</p>
<pre><code>'myclass::thread_buffer' muss zur laufzeit initialisiert/finalisiert werden
</code></pre>
<p>wie geht das nun richtig ?</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/802224</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/802224</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Sat, 04 Jun 2005 16:15:11 GMT</pubDate></item></channel></rss>