<?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[Statischen Semaphore innerhalb Threadmethode]]></title><description><![CDATA[<p>Hi</p>
<p>Wie löse ich folgendes Problem:</p>
<pre><code class="language-cpp">class test {

private:

	static int semaphore;

	static DWORD WINAPI runbla(LPVOID lp){
		// Eintreten in kritischen Bereich anhand semaphore Bsp.:
		semaphore = 1;
		return 0;
	}

public:

	void run(){
		CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)runbla,NULL,0,NULL);
	}

};

int main(int argc, char* argv[])
{
	test t;
	t.run();
	return 0;
}
</code></pre>
<p>test.obj : error LNK2001: unresolved external symbol &quot;private: static int test::semaphore&quot; (?semaphore@test@@0HA)</p>
<p>So viel ich weiss muss die Threadfunction statisch sein. Deshalb auch das Semaphore.</p>
<p>MfG Joe</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/169736/statischen-semaphore-innerhalb-threadmethode</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Jul 2026 13:59:58 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/169736.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 08 Jan 2007 13:47:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Statischen Semaphore innerhalb Threadmethode on Mon, 08 Jan 2007 13:47:06 GMT]]></title><description><![CDATA[<p>Hi</p>
<p>Wie löse ich folgendes Problem:</p>
<pre><code class="language-cpp">class test {

private:

	static int semaphore;

	static DWORD WINAPI runbla(LPVOID lp){
		// Eintreten in kritischen Bereich anhand semaphore Bsp.:
		semaphore = 1;
		return 0;
	}

public:

	void run(){
		CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)runbla,NULL,0,NULL);
	}

};

int main(int argc, char* argv[])
{
	test t;
	t.run();
	return 0;
}
</code></pre>
<p>test.obj : error LNK2001: unresolved external symbol &quot;private: static int test::semaphore&quot; (?semaphore@test@@0HA)</p>
<p>So viel ich weiss muss die Threadfunction statisch sein. Deshalb auch das Semaphore.</p>
<p>MfG Joe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1205650</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1205650</guid><dc:creator><![CDATA[*JoE*]]></dc:creator><pubDate>Mon, 08 Jan 2007 13:47:06 GMT</pubDate></item><item><title><![CDATA[Reply to Statischen Semaphore innerhalb Threadmethode on Mon, 08 Jan 2007 14:04:56 GMT]]></title><description><![CDATA[<p>Hi</p>
<p>Erstmal zu deinem Fehler (LNK 2001): Du musst &quot;semaphore&quot; noch außerhalb der Klasse deklarieren, also unter die Klasse noch ein &quot;int test::semaphore;&quot; schreiben. Wenn du die Klasse in eine Header- und Cppdatei auslagerst, dann gehört diese Zeile in die Cpp-Datei.<br />
Und richtig, die Thread-Func muss statisch sein <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>Und die Variable &quot;Semaphore&quot; soll anzeigen, ob ein Thread gerade läuft oder wie?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1205665</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1205665</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Mon, 08 Jan 2007 14:04:56 GMT</pubDate></item><item><title><![CDATA[Reply to Statischen Semaphore innerhalb Threadmethode on Mon, 08 Jan 2007 14:29:53 GMT]]></title><description><![CDATA[<p>Was soll den das werden? Ich sehe in dem Code viel Potential für Blödsinn wenn ich das mal so sagen darf... eine normale Variable (nix volatile, nix interlocked etc.) im Zusammenhang mit den Wörtern &quot;Thread&quot; und &quot;Sempahore&quot;... das riecht schonmal faul.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1205690</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1205690</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 08 Jan 2007 14:29:53 GMT</pubDate></item></channel></rss>