<?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 synchronisation]]></title><description><![CDATA[<p>hi,<br />
ich will 2 threads synchronisieren, thread 1 setzt zustände einer statemachine...thread2 reagier auf zustände der statemachine!<br />
Wäre folgendes ne gute Lösung für sowas?</p>
<pre><code>Pseudocode:
void thread1()
{
	static int i = 0;
	while(1)
	{
		i++;

		if(i % 7)
		{
			Send_Message(setsystemstate(AKTIVE));
		}
		else if(i % 55)
		{
			Send_Message(setsystemstate(INAKTIVE));
		}

		Sleep(10);
	}
}

void thread2()
{
	while(1)
	{
		WaitForSingleObject(systemstate, 10ms);
		// wenn WaitForSingleObject successfull dann wurde neuer systemstate gesetzt
                if (waitforsingleobject == successful)
                    systemstate = systemstate_aus_message;
                // else alten systemsate verwenden

		if(systemstate == AKTIVE)
			counter++;
		else if(systemsate == INAKTIVE);
			counter--;

		Sleep(10);
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/209221/thread-synchronisation</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Apr 2026 12:16:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/209221.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 27 Mar 2008 23:58:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to thread synchronisation on Thu, 27 Mar 2008 23:58:58 GMT]]></title><description><![CDATA[<p>hi,<br />
ich will 2 threads synchronisieren, thread 1 setzt zustände einer statemachine...thread2 reagier auf zustände der statemachine!<br />
Wäre folgendes ne gute Lösung für sowas?</p>
<pre><code>Pseudocode:
void thread1()
{
	static int i = 0;
	while(1)
	{
		i++;

		if(i % 7)
		{
			Send_Message(setsystemstate(AKTIVE));
		}
		else if(i % 55)
		{
			Send_Message(setsystemstate(INAKTIVE));
		}

		Sleep(10);
	}
}

void thread2()
{
	while(1)
	{
		WaitForSingleObject(systemstate, 10ms);
		// wenn WaitForSingleObject successfull dann wurde neuer systemstate gesetzt
                if (waitforsingleobject == successful)
                    systemstate = systemstate_aus_message;
                // else alten systemsate verwenden

		if(systemstate == AKTIVE)
			counter++;
		else if(systemsate == INAKTIVE);
			counter--;

		Sleep(10);
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1481789</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1481789</guid><dc:creator><![CDATA[cpp.]]></dc:creator><pubDate>Thu, 27 Mar 2008 23:58:58 GMT</pubDate></item><item><title><![CDATA[Reply to thread synchronisation on Fri, 28 Mar 2008 17:25:49 GMT]]></title><description><![CDATA[<p>schau dir mal CRITICAL_SECTION an</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1482332</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1482332</guid><dc:creator><![CDATA[JAyJay2]]></dc:creator><pubDate>Fri, 28 Mar 2008 17:25:49 GMT</pubDate></item></channel></rss>