<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sgt. Conker &#187; Threading</title>
	<atom:link href="http://www.sgtconker.com/category/xna/threading/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sgtconker.com</link>
	<description>We are &#34;absolutely fine&#34;</description>
	<lastBuildDate>Wed, 06 Jul 2011 13:29:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Code From The Forums</title>
		<link>http://www.sgtconker.com/2010/10/code-from-the-forums/</link>
		<comments>http://www.sgtconker.com/2010/10/code-from-the-forums/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 21:02:58 +0000</pubDate>
		<dc:creator>Captain boki</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Threading]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XNA 4.0]]></category>

		<guid isPermaLink="false">http://www.sgtconker.com/2010/10/code-from-the-forums/</guid>
		<description><![CDATA[Some code (well, more like library) announcements from the Creators Club OnlineAppHub forums.
First, there is GPF – WPF for XNA by genralhi (the blog links are in Russian), which looks interesting even though the full WPF might be a bit overkill for game UIs. Second, MicroMan6502 announces his EasyThreading library to “provide something to the [...]]]></description>
			<content:encoded><![CDATA[<p>Some code (well, more like library) announcements from the <a href="http://create.msdn.com/en-US/"><em><strike>Creators Club OnlineAppHub</strike></em></a> forums.</p>
<p>First, there is <a href="http://forums.create.msdn.com/forums/p/62833/385812.aspx">GPF – WPF for XNA</a> by <em>genralhi</em> (the blog links are in Russian), which looks interesting even though the full WPF might be a bit overkill for game UIs. Second, <em>MicroMan6502</em> announces his <a href="http://forums.create.msdn.com/forums/t/62966.aspx">EasyThreading</a> library to “provide something to the community”.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sgtconker.com/2010/10/code-from-the-forums/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Concurrent Programming in the Design of a 3D Game Engine</title>
		<link>http://www.sgtconker.com/2010/02/concurrent-programming-in-the-design-of-a-3d-game-engine/</link>
		<comments>http://www.sgtconker.com/2010/02/concurrent-programming-in-the-design-of-a-3d-game-engine/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 22:44:52 +0000</pubDate>
		<dc:creator>Captain boki</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Threading]]></category>
		<category><![CDATA[Game Architecture]]></category>
		<category><![CDATA[Game Engine Design]]></category>

		<guid isPermaLink="false">http://www.sgtconker.com/2010/02/concurrent-programming-in-the-design-of-a-3d-game-engine/</guid>
		<description><![CDATA[The GameCareerGuide.com site published an article by Jarret Tierney about Concurrent Programming in the Design of a 3D Game Engine (not specifically about concurrency in the XNA FX/.NET world but still a Good Read™).
We have taken an in depth look at what concurrency means and both its benefits and issues. While concurrency may still not [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.gamecareerguide.com/">GameCareerGuide.com</a> site published an article by Jarret Tierney about <a href="http://www.gamecareerguide.com/features/828/concurrent_programming_in_the_.php?">Concurrent Programming in the Design of a 3D Game Engine</a> (not specifically about concurrency in the XNA FX/.NET world but still a Good Read™).</p>
<blockquote cite="http://www.gamecareerguide.com/features/828/concurrent_programming_in_the_.php?page=5"><p>We have taken an in depth look at what concurrency means and both its benefits and issues. While concurrency may still not be frequently used in general purpose software, the use of multi-threaded programming in the gaming industry has sky-rocketed because of multi-core processors and game consoles like the Playstation 3. Designing a concurrent game engine is a complicated task that challenges programmers to think about how programs run in a different way.</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.sgtconker.com/2010/02/concurrent-programming-in-the-design-of-a-3d-game-engine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Article : Multi-threading your XNA</title>
		<link>http://www.sgtconker.com/2009/11/article-multi-threading-your-xna/</link>
		<comments>http://www.sgtconker.com/2009/11/article-multi-threading-your-xna/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 21:50:29 +0000</pubDate>
		<dc:creator>Sgt. Conker</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Threading]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.sgtconker.com/?p=533</guid>
		<description><![CDATA[In this tutorial you will learn how to use multi-threading in your XNA games. The tutorial starts with a short introduction about multi-threading, the Xbox 360 architecture,  and the advantages and disadvantages of using multi-threading for XNA games.]]></description>
			<content:encoded><![CDATA[<h4 style="text-align: center;">by <a href="http://www.catalinzima.com/">Catalin Zima</a></h4>
<p><strong>Contents:</strong></p>
<p>1. Introduction</p>
<p>2. A Look at Multithreading Primitives</p>
<p>3. Multithreading Update/Draw</p>
<p>4. Example: Balls</p>
<p>5. Conclusions</p>
<p>6. Downloads</p>
<p>7. References</p>
<p><span id="more-533"></span></p>
<p>In this tutorial you will learn how to use multi-threading in your XNA games. The tutorial starts with a short introduction about multi-threading, the Xbox 360 architecture,  and the advantages and disadvantages of using multi-threading for XNA games. This will be followed by a very brief look at the classes and primitives that we will use in the rest of the article. After this, the main part of this tutorial is focused on using multi-threading for the main game loop. You will learn how you can separate the code for drawing and updating you game and run the two tasks in parallel. There are other ways to use multi-threading in your games, but they will not be covered by this tutorial. As a closing word, we will draw some conclusions and look at future developments.</p>
<p><strong>1. Introduction</strong></p>
<p>As game developers, we always want our games to be better. We want better graphics, better physics, better A.I., and so on, just to make our customers happy. However, we always have so little time to do all of these. I'm not talking about implementation time, which is of little interest to our players, but about the running time. Players are really picky. They expect the games they play to run smooth and fluent, which means our games should run at 30 or even 60 FPS (Frames Per Second). This leaves us with 16.66 milliseconds in which we have to squeeze all the physics, graphics, gameplay and AI we want. For some games this is more than enough. For others, that is a painfully low threshold.</p>
<p>So what's this about multi-threading? Normally, your game starts and runs on a single thread, so all the tasks run sequentially one after the other. Thus, the total running time of a frame will be equal to the sum of the running times of each task done during that frame.</p>
<p><img src="http://www.sgtconker.com/wp-content/uploads/2009/11/dc3j5d6h_5cw54nzcm_b.jpg" alt="" /></p>
<p>Using multiple threads would mean taking some of these tasks, and running them in parallel, at the same time as other tasks are running. In this configuration, the total running time of a frame will be roughly equal to the running time of the slowest of these parallel sets of tasks. Thus, the overall frame time is lower than when using a single thread, so the performance of the game is higher, yielding better framerates and smoother animations.</p>
<p><img src="http://www.sgtconker.com/wp-content/uploads/2009/11/dc3j5d6h_6c7f2vbfn_b.jpg" alt="" /></p>
<p>There are a few important things you need to remember after looking at this picture.</p>
<ul>
<li> Not all tasks need to be parallelized. In this example, we left the input handling running serially. Maybe both game logic and animations need the input, or maybe you just feel better having a certain task run on its own, without anything else running in parallel. Just remember that it can be done, and in some cases you will probably want this to happen.</li>
<li> The tasks need to be independent from one another. As they are running in parallel, it's not that easy for them to communicate, so we need to have some mechanism to pass data between parallel tasks. Ideally, you would have completely independent tasks, but in a game, this is rarely possible. Animation needs physics and A.I. data, A.I. also needs physics, rendering needs information from all the other processes, and so on. We will look at this later in the article.</li>
<li> One of the most important things to remember it that the speed gained by using multi-threading is still limited by the speed of the slowest branch. In the example, even though we use two threads, the frame time is not quite half of the initial frame time. Even if we create a separate thread for each task, the running time of the frame will be at least the running time of the physics task (the slowest in our example). Also, communication and synchronization between threads introduces some overhead, which adds to the total frame time.</li>
</ul>
<p>Now let's see where will we run these threads. In the latest years, PCs have evolved and are now equipped with processors having 2 or 4 cores. This means that we can have up to 4 threads running completely independent of one another, and not sharing processor time. Of course, no one's limiting you to one thread per core, but it's better to do so with computationally intensive tasks. The Xbox 360 has a different architecture. It is equipped with a special IBM processor with 3 cores, each of them capable or running two independent hardware threads. So in total, we have 6 hardware threads on the 360. Unfortunately, two of them are reserved, and cannot be used by us, as they are used by the XNA Framework, and other system tasks. But having 4 hardware threads is not that bad either. Below we can see what these threads are.</p>
<table border="1" width="183">
<tbody>
<tr style="text-align: center;">
<td width="10%"><strong>Hardware Thread</strong></td>
<td width="5%"><strong>Core</strong></td>
<td><strong>Notes</strong></td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td><span style="color: #ff0000;">Not Available. Reserved for the XNA Framework</span></td>
</tr>
<tr>
<td>1</td>
<td>0</td>
<td>Available.</td>
</tr>
<tr>
<td>2</td>
<td>1</td>
<td><span style="color: #ff0000;">Not Available. Reserved for the XNA Framework</span></td>
</tr>
<tr>
<td>3</td>
<td>1</td>
<td>Available.</td>
</tr>
<tr>
<td>4</td>
<td>2</td>
<td>Available.</td>
</tr>
<tr>
<td>5</td>
<td>2</td>
<td>Available.</td>
</tr>
</tbody>
</table>
<p>So what are the advantages of using multi-threading for your games? The main advantages are greater performance, higher frame rates, possibility to add more complex simulations for physics, AI, or other things. The disadvantages are the added complexity needed to write your game for multiple threads. Many times, your game will run just fine on a single thread. Separating tasks and taking care of all issues associated with multi-threading is a complex task, and requires complex data structures and synchronization code and it may not be worth the effort. You need to have a good understanding of how threads and memory sharing works, or else your multi-threaded code might run even slower than your single-threaded code.<br />
Another great minus is that multi-threaded code is very hard to debug. The errors that occur because of the interaction between threads are very difficult to replicate and identify, and thus, difficult to remove. With that said, let's go on and see what classes and keywords you need to understand in order to follow this tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sgtconker.com/2009/11/article-multi-threading-your-xna/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

