<?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>Fishing Cactus development blog &#187; Programming</title>
	<atom:link href="http://blog.fishingcactus.com/index.php/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.fishingcactus.com</link>
	<description>We don't create games that look like others; we don't create games that play like others</description>
	<lastBuildDate>Thu, 02 Sep 2010 16:19:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>AiGameDev Conference 2010: EVE Online Characters</title>
		<link>http://blog.fishingcactus.com/index.php/2010/07/19/674/</link>
		<comments>http://blog.fishingcactus.com/index.php/2010/07/19/674/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 08:44:45 +0000</pubDate>
		<dc:creator>christophe.bernard</dc:creator>
				<category><![CDATA[Game Design]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ai]]></category>
		<category><![CDATA[aigamedev]]></category>
		<category><![CDATA[game]]></category>

		<guid isPermaLink="false">http://blog.fishingcactus.com/?p=674</guid>
		<description><![CDATA[UPDATE: post is now under the right author name.
During the AiGameDev Conference 2010 at Paris Claudio Pedica, a researcher at CADIA Labs, Reykjavik University, currently collaborating with CCP Games presented us their new social interaction system in a talk titled Human Territoriality for EVE Online&#8217;s Socially Smart Characters.

This was a short preview on how the space stations are [...]]]></description>
			<content:encoded><![CDATA[<p><em>UPDATE: post is now under the right author name.</em></p>
<p>During the <a href="http://aigamedev.com/" target="_blank">AiGameDev Conference 2010</a> at Paris Claudio Pedica, a researcher at <a href="http://cadia.ru.is/" target="_blank">CADIA Labs</a>, Reykjavik University, currently collaborating with <a href="http://www.ccpgames.com" target="_blank">CCP Games</a> presented us their new social interaction system in a talk titled Human Territoriality for EVE Online&#8217;s Socially Smart Characters.</p>
<p style="text-align: center;"><img class="aligncenter" style="border: 2px solid black;" src="http://files.aigamedev.com/coverage/GAIC10h_ClaudioPedica.large.jpg" alt="" width="216" height="324" /></p>
<p style="text-align: left;"><span id="more-674"></span>This was a short preview on how the space stations are going to be populated in the next EVE online expansion.</p>
<p>The main focus of the research conducted by CCP is based on the lack of feedback in games when it comes to interactions. For example if you pass besides a game character, he doesn’t notice you or in worse cases, if you bump into him, the most common reaction is that he won&#8217;t even step aside and your character stops dumbly like when facing a wall! Fortunately, not all games react like this. In GTA when you hit someone or pass close to him he steps aside or even says something to you.</p>
<p>What the guys at CCP are trying to do is to recreate an interaction system based on how humans practically cope with interactions and how they react to other people’s physical presence.</p>
<p>In the demos shown we could see the﻿ character move close to a group of NPCs; when close enough, the group understands that this character wants to be part of their group so they take a step aside to form a bigger but still homogeneous group.<img src="file:///C:/Users/FishingCactus_Andrea/Desktop/ccp01.jpg" alt="" /></p>
<p style="text-align: center;"><a href="http://blog.fishingcactus.com/wp-content/uploads/2010/07/ccp01.jpg"><img style="border: 2px solid black;" title="ccp01" src="http://blog.fishingcactus.com/wp-content/uploads/2010/07/ccp01-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>The “circle” itself is, in this system, the interaction unit; each character and group possesses one and each unit is designed for a particular type of interaction.</p>
<p>1) First there is the personal circle which defines the limit of the body area.</p>
<p>2) The external circle is used for the close social interactions like dialogs or people walking near (also true for groups).</p>
<p>3) An inner circle is also defined by the participants of the group: a circle defines its body and the external circle of it. In another example we saw one participant moving a few steps from his former position and the rest of the group following him to recreate the circle.</p>
<p><img src="file:///C:/Users/FishingCactus_Andrea/Desktop/ccp01.png" alt="" /></p>
<p>I actually don&#8217;t play EVE Online at all and I don&#8217;t really know what they are planning to do with the new space stations system but having this feature is über-cool and I think it would really improve the experience of the players (at least contributing to a more immersive experience).</p>
<p>Having people walking from one spot to another or joining conversations or even reacting to the players&#8217; presence will surely make us feel more in a real living world. When you think that some games only feature static NPCs, this talk gets even more impressing!</p>
<p>Human Territoriality for EVE Online&#8217;s Socially Smart Characters by Claudio Pedica can be downloaded from the <a href="http://aigamedev.com/" target="_blank">AiGameDev website</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.fishingcactus.com/index.php/2010/07/19/674/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open Source localization tool</title>
		<link>http://blog.fishingcactus.com/index.php/2010/03/30/open-source-localization-tool/</link>
		<comments>http://blog.fishingcactus.com/index.php/2010/03/30/open-source-localization-tool/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 13:50:13 +0000</pubDate>
		<dc:creator>Julien Hamaide</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.fishingcactus.com/?p=377</guid>
		<description><![CDATA[
Fishing Cactus has the pleasure to announce that the team has started a localization tool. And the best for you, the tool will be released as open source ( the licence must still be decided ), as a google code project.
Our previous experience with localization has been pretty painful. Everybody can remember those German texts [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.fishingcactus.com/wp-content/uploads/2010/03/localization-300x300.jpg"><img src="http://blog.fishingcactus.com/wp-content/uploads/2010/03/localization-300x300.jpg" alt="" title="localization" width="150" height="150" class="alignright size-full wp-image-380" /></a><br />
Fishing Cactus has the pleasure to announce that the team has started a localization tool. And the best for you, the tool will be released as open source ( the licence must still be decided ), as a google code project.</p>
<p>Our previous experience with localization has been pretty painful. Everybody can remember those German texts that were at least twice the control size. From our experience, we thought a tool could be use to help managing and creating localization. Especially when the task is outsourced to some studio living in another time zone. The goal is to provide an interface between the designer and the &#8220;localizators&#8221;. The tool will contain information about text extent and will provide a preview of the text inside its control.</p>
<p>The feature list will be announced in the following weeks. But here is a preview :<br />
Qt has been chosen as Mojito, our proprietary engine, runs on the 3 main OSes. The file format will be XML, but the tool architecture will ease the implementation of other format as well. Platform specific text can be inserted ( such as specific hardware name ). Support for exotic language such as Chinese and Arabian is planned. </p>
<p>As the tool matures, we will discuss design choices we made on this blog. Developers in charge of a specific feature will also have the opportunity to expose their work.</p>
<p>Stay tuned, the first code release is approaching. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.fishingcactus.com/index.php/2010/03/30/open-source-localization-tool/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>What do you drink? Piña COLLADA!</title>
		<link>http://blog.fishingcactus.com/index.php/2010/02/03/what-do-you-drink-pina-collada/</link>
		<comments>http://blog.fishingcactus.com/index.php/2010/02/03/what-do-you-drink-pina-collada/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 10:23:43 +0000</pubDate>
		<dc:creator>julien.bartels</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.fishingcactus.com/?p=302</guid>
		<description><![CDATA[In the best company of the world and with the most talented team (Belgians are famous for their self-derision), it is mandatory to use the most advanced technologies for creating our games. Of course just for your pleasure.
This is why we decided to automate our &#8220;Game Content Pipeline&#8221; with a continuous integration process. To do this, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.fishingcactus.com/wp-content/uploads/2010/02/pinacollada.jpg"><img src="http://blog.fishingcactus.com/wp-content/uploads/2010/02/pinacollada.jpg" alt="Collada Exporter / Importer in Mojito Pipeline" title="pinacollada" width="115" height="150" class="alignleft size-full wp-image-318" /></a>In the best company of the world and with the most talented team (Belgians are famous for their self-derision), it is mandatory to use the most advanced technologies for creating our games. Of course just for your pleasure.</p>
<p>This is why we decided to automate our &#8220;Game Content Pipeline&#8221; with a continuous integration process. To do this, we used &#8220;Hudson&#8221; simply because it wasn&#8217;t too difficult to implement within the Mojito Engine and secondly because the solution is quite complete.</p>
<p>One of the first step I had to undertake within this pipeline was to import all assets from a graphical software and export them to a format our engine will be able to use. <a href="http://www.khronos.org/collada/">Collada</a> is perfect for this job and this is why we went on to create a Collada importer and a viewer which runs in the Mojito Engine.</p>
<p>For the first time we are proud to present you, the star of all stars, &#8220;Mr. Duck&#8221; from Mojito’s viewer.</p>
<p><center><a href="http://blog.fishingcactus.com/wp-content/uploads/2010/02/canard_final.jpg"><img src="http://blog.fishingcactus.com/wp-content/uploads/2010/02/canard_final.jpg" alt="Pina Collada and Mojito" title="canard_final" width="350" height="316" class="aligncenter size-full wp-image-332" /></a></center><br />
<center>« Good night and good duck! »</center></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.fishingcactus.com/index.php/2010/02/03/what-do-you-drink-pina-collada/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mojito on Linux &#8211; Diary #2</title>
		<link>http://blog.fishingcactus.com/index.php/2010/02/01/mojito-on-linux-diary-2/</link>
		<comments>http://blog.fishingcactus.com/index.php/2010/02/01/mojito-on-linux-diary-2/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 15:18:54 +0000</pubDate>
		<dc:creator>Christophe Clementi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mojito]]></category>
		<category><![CDATA[porting]]></category>

		<guid isPermaLink="false">http://blog.fishingcactus.com/?p=296</guid>
		<description><![CDATA[As you may have read on this blog a week ago we began porting the Mojito Engine on the GNU/Linux platform.
It&#8217;s going pretty well, faster than I originally expected. I started by translating the display part, initially running with DirectX on the Windows version and now running with OpenGL. The result was as expected, and [...]]]></description>
			<content:encoded><![CDATA[<p>As you may have read on this blog a week ago we began porting the Mojito Engine on the GNU/Linux platform.</p>
<p>It&#8217;s going pretty well, faster than I originally expected. I started by translating the display part, initially running with DirectX on the Windows version and now running with OpenGL. The result was as expected, and that&#8217;s how we were able to post the first screenshot you&#8217;ve seen in an earlier post. We rapidly figured out that the input system provided by GLUT was not exactly what we needed. So we decided to rewrite that specific engine part with SDL in order to have not only the keyboard but the joypad too!</p>
<p>And I’m proud to say that everything is now fully working <img src='http://blog.fishingcactus.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  My next task will be to port the sound system of the engine.</p>
<p>As you can see in <a href="http://2dboy.com/2009/10/26/pay-what-you-want-birthday-sale-wrap-up/" target="_blank">World of Goo</a>, created by 2D Boy, they had about 17% of their sales on the Linux platform. It looks like a lot of open source gamers are just waiting for some stuff to play on the penguin!</p>
<p>So, be ready, Linux-users! Because in a not so distant future, you will be able to run on your hardware some Fishing Cactus games and show off in front of all your friends!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.fishingcactus.com/index.php/2010/02/01/mojito-on-linux-diary-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Linux version of Mojito Engine on its way!</title>
		<link>http://blog.fishingcactus.com/index.php/2010/01/22/linux-version-of-mojito-engine-on-its-way/</link>
		<comments>http://blog.fishingcactus.com/index.php/2010/01/22/linux-version-of-mojito-engine-on-its-way/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 13:50:38 +0000</pubDate>
		<dc:creator>Christophe Clementi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mojito]]></category>

		<guid isPermaLink="false">http://blog.fishingcactus.com/?p=274</guid>
		<description><![CDATA[With the mondial crysis, it&#8217;s important to think about the people who are in need. They maybe can&#8217;t buy a fully functional Mac or an expensive Windows licence&#8230;
Luckily, they can discover the joy of working with the open-source &#8220;OS for the poor&#8221;, Linux!
We have already improved the most current platforms on the market with our [...]]]></description>
			<content:encoded><![CDATA[<p>With the mondial crysis, it&#8217;s important to think about the people who are in need. They maybe can&#8217;t buy a fully functional Mac or an expensive Windows licence&#8230;</p>
<p>Luckily, they can discover the joy of working with the open-source &#8220;OS for the poor&#8221;, Linux!</p>
<p>We have already improved the most current platforms on the market with our kickass Mojito Engine, and we are now currently working on the Linux version.</p>
<p>And just because we like you guys, readers of this blog, we will offer you the exclusivity of the year : the first screenshot of a not-so-mysterious project, running on Ubuntu!</p>
<p style="text-align: center"><a href="http://blog.fishingcactus.com/wp-content/uploads/2010/01/first-screen-linux1.jpg"><img class="size-medium wp-image-281 aligncenter" style="border: 1px solid black" src="http://blog.fishingcactus.com/wp-content/uploads/2010/01/first-screen-linux1-300x149.jpg" alt="Awesome Mojito on Linux" width="300" height="149" /></a></p>
<p>I know how much it&#8217;s beautiful, but don&#8217;t cry yet, keep your tears when it will be fully functional so stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.fishingcactus.com/index.php/2010/01/22/linux-version-of-mojito-engine-on-its-way/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Cross Platform Thread Local Storage (cont&#8217;d)</title>
		<link>http://blog.fishingcactus.com/index.php/2009/12/21/cross-platform-thread-local-storage-contd/</link>
		<comments>http://blog.fishingcactus.com/index.php/2009/12/21/cross-platform-thread-local-storage-contd/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 16:36:55 +0000</pubDate>
		<dc:creator>Julien Hamaide</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[thread local storage]]></category>

		<guid isPermaLink="false">http://blog.fishingcactus.com/?p=95</guid>
		<description><![CDATA[In the first post, I introduced the thread local storage we use across all platforms. The main goal was to provide similar interface and features as __declspec( thread ) variables provided by some compilers. The previous post reproduced in pure C++ what gcc and cl.exe allowed as extension, but on every platform that supports at [...]]]></description>
			<content:encoded><![CDATA[<p>In the first post, I introduced the thread local storage we use across all platforms. The main goal was to provide similar interface and features as __declspec( thread ) variables provided by some compilers. The previous post reproduced in pure C++ what gcc and cl.exe allowed as extension, but on every platform that supports at least 1 thread local storage. The goal of this post is to extend the existing system to all types including complex classes.</p>
<p><span id="more-95"></span><br />
Compilers only allow TLS on POD ( Plain Old Data ) types, no object can be used. This extension allows to use all types of objects, as long as it has a default constructor.</p>
<p>Allowing complex types in TLS leads to 2 challenges : allocating enough memory to contain the object and calling constructors and destructors on thread startup and exit.</p>
<p>In the <a href="http://blog.fishingcactus.com/index.php/2009/07/20/cross-platform-thread-local-storage/trackback/">previous version</a>, the memory used for TLS was a table of 4 bytes-long items. We could have used this system to store a pointer to the complex object, but we tried to avoid dereferences as much as possible. The system is then changed to contain any size needed. Each TLS instance contains the index inside a buffer. This buffer is created for each new thread and contains the memory needed to store all objects. The base class constructor now takes the size of the object and tracks the total size in a static variable. When the thread starts, the buffer is allocated and all objects are constructed inside this buffer. But more on this later. This technique has the advantage of allocating a single chunk of memory for a thread. It avoids memory waste of multiple allocations.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">&nbsp;
<span style="color: #0000ff;">class</span> ThreadLocalStorageBase
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">int</span> m_buffer_size <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">static</span> TLSIndex m_tls_identifier<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> m_index<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">protected</span><span style="color: #008080;">:</span>
    ThreadLocalStorageBase<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> object_size <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        object_size <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span> object_size <span style="color: #000040;">+</span> Alignment <span style="color: #000040;">-</span> <span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span> ~<span style="color: #008000;">&#40;</span> Alignment <span style="color: #000040;">-</span> <span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        m_index <span style="color: #000080;">=</span> m_buffer_size<span style="color: #008080;">;</span>
        m_buffer_size <span style="color: #000040;">+</span><span style="color: #000080;">=</span> object_size<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">void</span> <span style="color: #000040;">*</span> GetThreadLocalStorage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span> 
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span> local_storage_table <span style="color: #000080;">=</span> <span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span><span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span> TLSGet<span style="color: #008000;">&#40;</span> m_tls_identifier <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #000040;">&amp;</span>local_storage_table<span style="color: #008000;">&#91;</span> m_index <span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">typename</span> T<span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">class</span> ThreadLocalStorage<span style="color: #000080;">&lt;</span>T<span style="color: #000080;">&gt;</span> <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> ThreadLocalStorageBase
<span style="color: #008000;">&#123;</span>
    ThreadLocalStorage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080;">:</span> ThreadLocalStorageBase<span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span> T <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>OS TLS has the property to initialize the value to zero the first time a thread accesses it. As we support any class, we need to provide a way to construct the objects. We decided to initialize all variables before entering the thread function. If variables are not used frequently, a lazy initialization mechanism can be implemented. In Mojito, a class encapsulates the OS thread object. We have then the place to call this initialization. The best mechanism depends on the way you will use TLS variables. </p>
<p>In both cases, when the thread is about to end, the allocated memory must be freed. So a call to the TLS finalizer must be done. ( pthread allows a destructor function to be registered, so you can take advantage of it ). Once again, in Mojito, the thread class is taking care of it.</p>
<p>A question that might have arose : how do you have access to all variables spread across the code? The trick is quite simple : in the constructor, register the variable into a single-linked list. This technique ensures that as soon as <em>main</em> is entered, the linked list is complete. I discovered this trick in the command line option package of <a href="http://llvm.org/">LLVM</a></p>
<p>As we have a class for each type, a base class has been created. It takes care of creating the list and provides the functions to initialize and finalize the variables. It also keeps track of accessing the thread local buffer.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> ThreadLocalStorageBase
<span style="color: #008000;">&#123;</span>
    ...
    <span style="color: #007788;">ThreadLocalStorageBase</span> <span style="color: #000040;">*</span> m_next<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">static</span> ThreadLocalStorageBase <span style="color: #000040;">*</span> m_first <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    ThreadLocalStorageBase<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> object_size <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        ...
        <span style="color: #007788;">m_next</span> <span style="color: #000080;">=</span> m_first<span style="color: #008080;">;</span>
        m_first <span style="color: #000080;">=</span> <span style="color: #0000dd;">this</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
     <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> StartupOnThreadEnter<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
     <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">void</span> <span style="color: #000040;">*</span> local_storage_table<span style="color: #008080;">;</span>
&nbsp;
        local_storage_table <span style="color: #000080;">=</span> <span style="color: #0000dd;">malloc</span><span style="color: #008000;">&#40;</span> m_buffer_size <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000dd;">memset</span><span style="color: #008000;">&#40;</span> local_storage_table, <span style="color: #0000dd;">0</span>, m_buffer_size <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        TLSSet<span style="color: #008000;">&#40;</span> m_tls_identifier, <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>local_storage_table <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        ThreadLocalStorageBase <span style="color: #000040;">*</span> current <span style="color: #000080;">=</span> m_first<span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span> current <span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            current<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>InitializeObject<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
            current <span style="color: #000080;">=</span> current<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>m_next<span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> CleanupOnThreadExit<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
       ThreadLocalStorageBase <span style="color: #000040;">*</span> current <span style="color: #000080;">=</span> m_first<span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span> current <span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            current<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>FinalizeObject<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
            current <span style="color: #000080;">=</span> current<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>m_next<span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0000dd;">free</span><span style="color: #008000;">&#40;</span> TLSGet<span style="color: #008000;">&#40;</span> m_tls_identifier <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">protected</span><span style="color: #008080;">:</span>
&nbsp;
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> InitializeObject<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> FinalizeObject<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>When the base class is in place, here are the modifications made to the subclass</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span> <span style="color: #0000ff;">typename</span> T <span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">class</span> ThreadLocalStorage <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> ThreadLocalStorageBase
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    operator <span style="color: #0000ff;">const</span> T<span style="color: #000040;">&amp;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">void</span> <span style="color: #000040;">*</span> thread_local_storage <span style="color: #000080;">=</span> GetThreadLocalStorage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #000040;">*</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span>T<span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span> thread_local_storage <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    ThreadLocalStorage <span style="color: #000040;">&amp;</span> operator<span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> T <span style="color: #000040;">&amp;</span> value <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">void</span> <span style="color: #000040;">*</span> thread_local_storage <span style="color: #000080;">=</span> GetThreadLocalStorage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #000040;">*</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span>T<span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span> thread_local_storage <span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> value<span style="color: #008080;">;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #000040;">*</span><span style="color: #0000dd;">this</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">protected</span><span style="color: #008080;">:</span>
&nbsp;
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> InitializeObject<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000dd;">new</span><span style="color: #008000;">&#40;</span> GetThreadLocalStorage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> T<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> FinalizeObject<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">static_cast</span><span style="color: #000080;">&lt;</span>T<span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span> GetThreadLocalStorage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>~T<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>We now have a complete implementation of TLS that supports all types of object. But what if you wanted to initialize your variable to a specific value. This last modifications uses the container object to store a default value and use it when initializing the TLS instance.</p>
<p>The code is very simple. We just include a constant instance of the variable&#8217;s type, that we fill using the constructor. We then provide this instance to the constructor.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span> <span style="color: #0000ff;">typename</span> T <span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">class</span> ThreadLocalStorage <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> ThreadLocalStorageBase
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">const</span> T m_default_value<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    ThreadLocalStorage<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> T <span style="color: #000040;">&amp;</span> default_value <span style="color: #000080;">=</span> T<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">:</span>
        ThreadLocalStorageBase<span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span> T <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span>,
        m_default_value<span style="color: #008000;">&#40;</span> default_value <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">protected</span><span style="color: #008080;">:</span>
&nbsp;
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> InitializeObject<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000dd;">new</span><span style="color: #008000;">&#40;</span> GetThreadLocalStorage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> T<span style="color: #008000;">&#40;</span> value <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> FinalizeObject<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">static_cast</span><span style="color: #000080;">&lt;</span>T<span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span> GetThreadLocalStorage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>~T<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>This concludes this pair of posts on Thread Local Storage as we use them in Mojito. Comments are warmly welcomed. Special thanks to <a href="http://www.bjoernknafla.com/Home.html">Bjoern Knafla</a> for his comments.</p>
<p>The source code can be found <a href="http://www.fishingcactus.com/blog/TLS2.zip">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.fishingcactus.com/index.php/2009/12/21/cross-platform-thread-local-storage-contd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cross Platform Thread Local Storage</title>
		<link>http://blog.fishingcactus.com/index.php/2009/07/20/cross-platform-thread-local-storage/</link>
		<comments>http://blog.fishingcactus.com/index.php/2009/07/20/cross-platform-thread-local-storage/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 14:40:02 +0000</pubDate>
		<dc:creator>Julien Hamaide</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.fishingcactus.com/index.php/2009/07/20/cross-platform-thread-local-storage/</guid>
		<description><![CDATA[It&#8217;s been a while since I post something technical here. We are currently really busy on our new secret project, but I have something to share.
Some compilers have an interesting property : __declspec(thread) for Microsoft cl.exe, __thread for Gcc. By using this declaration on a global variable, a copy of the variable is created for [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since I post something technical here. We are currently really busy on our new secret project, but I have something to share.</p>
<p>Some compilers have an interesting property : <a href="http://msdn.microsoft.com/en-us/library/9w1sdazb(VS.80).aspx">__declspec(thread)</a> for Microsoft cl.exe, <a href="http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Thread-Local.html">__thread</a> for Gcc. By using this declaration on a global variable, a copy of the variable is created for each thread. This is known as a <a href="http://en.wikipedia.org/wiki/Thread-local_storage">Thread Local Storage</a> (TLS). You can always use direct calls to the system&#8217;s API ( <a href="http://msdn.microsoft.com/en-us/library/ms686991(VS.85).aspx">TLSGetValue and TLSSetValue</a> for Windows, <a href="http://www.opengroup.org/onlinepubs/009695399/functions/pthread_setspecific.html">pthread_getspecific and pthread_setspecific</a> for POSIX systems), but using automatic TLS variable is very comfy. As you may know, Mojito is available on several platforms, some of them does not provide those kind of variables. And if provided, those variables are limited to POD (Plain Ol&#8217; data) variables. So we search for a solution that is close to what compiler can offer.</p>
<p><span id="more-86"></span></p>
<p>The solution presented here provides a mean to create such cosy variables, with a bonus : support for non-pod data.<br />
To emulate the __thread specifications, the requirements are :<br />
- The TLS variable should behave as a normal one.<br />
- Memory should not be allocated if not necessary.<br />
- Destruction of object must be properly done.<br />
- Declaration should not be cryptic.</p>
<p>Solution : ThreadLocalStorage&lt;MyClass&gt; g_SomeThreadLocalStorageVariable;</p>
<p>The template class should have the following interface to conform to the specification :</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">typename</span> T<span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">class</span> ThreadLocalStorage
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    ThreadLocalStorage<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> T <span style="color: #000040;">&amp;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// Use to allow initialization of default value</span>
    operator <span style="color: #0000ff;">const</span> T<span style="color: #000040;">&amp;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
    ThreadLocalStorage <span style="color: #000040;">&amp;</span> operator<span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> T <span style="color: #000040;">&amp;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The major drawback of this technique : it only works in C++, as it uses operators of classes.<br />
With this class, you can implement both operator in terms of getting and setting the value contains in the OS&#8217; TLS. Generally, the TLS API provides 4 to 8 bytes of memory, generally to store pointers or basic types. This post will cover POD types, while complex types will be covered in the next post.</p>
<p>The code needed to fetch and store TLS is the same for each type of variable. It then makes sense to create a base class for this template.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> ThreadLocalStorageBase
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">protected</span><span style="color: #008080;">:</span>
&nbsp;
    ThreadLocalStorageBase<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
     <span style="color: #008000;">&#123;</span>
         m_index <span style="color: #000080;">=</span> m_instance_count<span style="color: #008080;">;</span>
         <span style="color: #000040;">++</span> m_instance_count<span style="color: #008080;">;</span> <span style="color: #666666;">// Not Thread safe</span>
     <span style="color: #008000;">&#125;</span>
&nbsp;
     <span style="color: #0000ff;">void</span> <span style="color: #000040;">*</span> GetThreadLocalStorage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span> 
     <span style="color: #008000;">&#123;</span>
         <span style="color: #0000ff;">void</span> <span style="color: #000040;">**</span> local_storage_table <span style="color: #000080;">=</span> <span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">void</span><span style="color: #000040;">**</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span> TLSGet<span style="color: #008000;">&#40;</span> m_tls_identifier <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
         <span style="color: #0000ff;">return</span> <span style="color: #000040;">&amp;</span>local_storage_table<span style="color: #008000;">&#91;</span> m_index <span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
     <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">int</span> m_index<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">int</span> m_instance_count<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">static</span> TLSIndex m_tls_identifier<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The sample code provided only use a single OS&#8217; TLS to store all home-made TLS. The reason is quite simple : the number of TLS an OS provides vary greatly and can be as few as 2. In Mojito we decided that having multiple versions of this code is not usefull until we know the current implementation causes a performance or a memory problem. So we kept this code for all platforms. If you want to adapt it to your platform, you only have to override 4 methods TLSCreate, TLSGet, TLSSet, TLSDestroy.</p>
<p>You may have noticed the m_tls_identifier variable. This is where we store the OS TLS index. To initialize it, you must call <em>ThreadLocalStorageBase::Initialize</em> before your first thread starts. The <em>ThreadLocalStorageBase::Finalize</em> must be called after all threads have returned.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> ThreadLocalStorageBase
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Initialize<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
         <span style="color: #666666;">//Must be called before any thread is started ( not thread safe at all )</span>
         m_tls_identifier <span style="color: #000080;">=</span> TLSCreate<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Finalize<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #666666;">//Must be called after all threads have been stopped ( not thread safe at all )</span>
        TLSDestroy<span style="color: #008000;">&#40;</span> m_tls_identifier <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The next question is how the OS&#8217; Tls gets initialized. The first way, not shown here, is to poll the output of the OS&#8217; Tls. If it equals to zero, it has not been initialized yet. It&#8217;s a lazy initialization. But it comes at the price of testing the value each time you access the variable. I have decided to pre-initialized it. Our threads are encapsulated in a class, so it&#8217;s easy to enforce the call to a function before giving hand to the user&#8217;s thread function. Same reasoning for deletion of memory. Not all systems allow the registration of destructors as pthread_key_create does. Again, using a class eases the use of a finalization function.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> ThreadLocalStorageBase
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> StartupOnThreadEnter<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">void</span> <span style="color: #000040;">*</span> local_storage_table<span style="color: #008080;">;</span>
&nbsp;
        local_storage_table <span style="color: #000080;">=</span> <span style="color: #0000dd;">malloc</span><span style="color: #008000;">&#40;</span> m_instance_count <span style="color: #000040;">*</span> <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000dd;">memset</span><span style="color: #008000;">&#40;</span> local_storage_table, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> m_instance_count <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        TLSSet<span style="color: #008000;">&#40;</span> m_tls_identifier, <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>local_storage_table <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> CleanupOnThreadExit<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000dd;">free</span><span style="color: #008000;">&#40;</span> TLSGet<span style="color: #008000;">&#40;</span> m_tls_identifier <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The ThreadLocalStorage class is shown hereunder, even if I can already hear some guy shouting about aliasing rules <img src='http://blog.fishingcactus.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span> <span style="color: #0000ff;">typename</span> T <span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">class</span> ThreadLocalStorage <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> ThreadLocalStorageBase
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
&nbsp;
    static_assert<span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span> T <span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;=</span> <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    operator <span style="color: #0000ff;">const</span> T<span style="color: #000040;">&amp;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">void</span> <span style="color: #000040;">*</span> thread_local_storage <span style="color: #000080;">=</span> GetThreadLocalStorage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #000040;">*</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span>T<span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span> thread_local_storage <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    ThreadLocalStorage <span style="color: #000040;">&amp;</span> operator<span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> T <span style="color: #000040;">&amp;</span> value <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">void</span> <span style="color: #000040;">*</span> thread_local_storage <span style="color: #000080;">=</span> GetThreadLocalStorage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #000040;">*</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span>T<span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span> thread_local_storage <span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> value<span style="color: #008080;">;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #000040;">*</span><span style="color: #0000dd;">this</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>The system is ready to go online. The sample code does not spawn thread, but the code displayed here shows how the system should be used :</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">ThreadLocalStorage<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> g_TestSmall<span style="color: #008080;">;</span>
<span style="color: #666666;">// ThreadLocalStorage&lt;std::string&gt; g_TestBig; Will be possible in next post</span>
&nbsp;
<span style="color: #0000ff;">void</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    ThreadLocalStorageBase<span style="color: #008080;">::</span><span style="color: #007788;">Initialize</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    ThreadLocalStorageBase<span style="color: #008080;">::</span><span style="color: #007788;">StartupOnThreadEnter</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    g_TestSmall <span style="color: #000080;">=</span> <span style="color: #0000dd;">1234</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> a <span style="color: #000080;">=</span> g_TestSmall<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">// Do some stuff, such as spawning threads    </span>
&nbsp;
    ThreadLocalStorageBase<span style="color: #008080;">::</span><span style="color: #007788;">CleanupOnThreadExit</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    ThreadLocalStorageBase<span style="color: #008080;">::</span><span style="color: #007788;">Finalize</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> thread_function<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #666666;">//signature depends on OS</span>
<span style="color: #008000;">&#123;</span>
    ThreadLocalStorageBase<span style="color: #008080;">::</span><span style="color: #007788;">StartupOnThreadEnter</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    g_TestSmall <span style="color: #000080;">=</span> <span style="color: #0000dd;">5678</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> a <span style="color: #000080;">=</span> g_TestSmall<span style="color: #008080;">;</span>
&nbsp;
    ThreadLocalStorageBase<span style="color: #008080;">::</span><span style="color: #007788;">CleanupOnThreadExit</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>In the next post, I&#8217;ll explain how to handle complex class ( at least non-POD types ). This can be useful to store, for example, smart pointers. It will also talk about default values (other than zero of course).</p>
<p>While this technique is surely not to be used in hot spot of your code, it provides a simple way to have thread local variable. For example, storing the last error occurred, storing a non-thread safe logger, &#8230; Most of the use we have is in debug or for storing thread local memory allocator.</p>
<p>The <a href="http://www.fishingcactus.com/blog/TLS1.zip">sample code</a> includes implementation for win32 and posix with an VC2005 and a xcode project. But our version of this code also runs on all consoles. Feel free to comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.fishingcactus.com/index.php/2009/07/20/cross-platform-thread-local-storage/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>GDC09 : Parallelism in AI &amp; AIGamedev.net conf</title>
		<link>http://blog.fishingcactus.com/index.php/2009/07/05/gdc09-parallelism-in-ai-aigamedevnet-conf/</link>
		<comments>http://blog.fishingcactus.com/index.php/2009/07/05/gdc09-parallelism-in-ai-aigamedevnet-conf/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 09:44:55 +0000</pubDate>
		<dc:creator>Julien Hamaide</dc:creator>
				<category><![CDATA[Company life]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.fishingcactus.com/index.php/2009/07/05/gdc09-parallelism-in-ai-aigamedevnet-conf/</guid>
		<description><![CDATA[At last GDC, I had the chance to talk about multithreading applied to AI. The talk was part of the AI summit. The summit was a great experience and I would recommend it to anybody interested in AI. I was also invited to talk about multithreading at the AIGameDev.net conference. You can find the notes [...]]]></description>
			<content:encoded><![CDATA[<p>At last GDC, I had the chance to talk about multithreading applied to AI. The talk was part of the AI summit. The summit was a great experience and I would recommend it to anybody interested in AI. I was also invited to talk about multithreading at the <a href="http://aigamedev.com/">AIGameDev.net conference</a>. You can find the notes and slides on the website. Gamedev.net also covered the <a href="http://www.gamedev.net/reference/business/features/parisAI09/">event<br />
</a></p>
<p>It&#8217;s been a while since I posted a technical article, but I&#8217;ve one nearly ready to go. It will talk about Thread Local Storage.</p>
<p>The slides from GDC can be download <a href="http://www.fishingcactus.com/files/GDC09AI.pdf">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.fishingcactus.com/index.php/2009/07/05/gdc09-parallelism-in-ai-aigamedevnet-conf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Banana Scrum</title>
		<link>http://blog.fishingcactus.com/index.php/2009/04/15/banana-scrum/</link>
		<comments>http://blog.fishingcactus.com/index.php/2009/04/15/banana-scrum/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 20:31:39 +0000</pubDate>
		<dc:creator>Bruno Urbain</dc:creator>
				<category><![CDATA[Company life]]></category>
		<category><![CDATA[Game Design]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.fishingcactus.com/index.php/2009/04/15/banana-scrum/</guid>
		<description><![CDATA[Fishing Cactus is proud to announce that we are using Banana Scrum web management tool to track the progress of our projects using Scrum methodology of course. We are currently evaluating the tool with two internal projects.
And it&#8217;s free.
Banana Scrum tool includes the following features:
•	project backlog with tagging and intuitive sorting through drag and drop, [...]]]></description>
			<content:encoded><![CDATA[<p><img id="image54" src="http://blog.fishingcactus.com/wp-content/uploads/2009/04/banane.jpg" alt="Banana Phone?" align="left" hspace="12" />Fishing Cactus is proud to announce that we are using <a href="http://www.bananascrum.com/">Banana Scrum</a> web management tool to track the progress of our projects using Scrum methodology of course. We are currently evaluating the tool with two internal projects.</p>
<p>And it&#8217;s free.</p>
<p><a href="http://www.bananascrum.com/">Banana Scrum</a> tool includes the following features:</p>
<p>•	project backlog with tagging and intuitive sorting through drag and drop, which allows you to put there items that need to be done in the project</p>
<p>•	sprint planning that allows you to assign items with tasks to the sprint</p>
<p>•	sprint backlog where you can add tasks,expected time of doing it and sign them to team members</p>
<p>•	impediment list where you can place encountered difficulties during the sprint and add it&#8217;s description</p>
<p>•	file uploading for each item to be done in the sprint</p>
<p>•	tags managing which allows you to add new tags and mark your tasks</p>
<p>•	CSV export that will export your backlog items to CSV file</p>
<p>•	burndown chart that shows you on a diagram if your sprint is feeling fine</p>
<p>•	admin panel with users managing and project managing options </p>
<p>•	different roles including Product Owner, Scrum Master and Team Member</p>
<p>•	intuitive, easy to use user interface</p>
<p>•	separate accounts with multiple projects and users</p>
<p>If you want to know more about <a href="http://www.bananascrum.com/">Banana Scrum</a> you can go here or watch a small presentation video <a href="http://www.codesprinters.com/uploads/videos/Banana_Good_2008-02-25_1539.swf">here</a>.</p>
<p>You wonder why this tool has such a silly name? Remember the <a href="http://agilemanifesto.org/">Agile Manifesto</a>? &#8220;Individuals and interactions over processes and tools&#8221;. This is just a tool, nice and useful but just a tool. They don&#8217;t want to get too pompous about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.fishingcactus.com/index.php/2009/04/15/banana-scrum/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fixing C++ static and global variable initialization</title>
		<link>http://blog.fishingcactus.com/index.php/2009/01/28/fixing-c-static-and-global-variable-initialization/</link>
		<comments>http://blog.fishingcactus.com/index.php/2009/01/28/fixing-c-static-and-global-variable-initialization/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 14:47:54 +0000</pubDate>
		<dc:creator>Julien Hamaide</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.fishingcactus.com/index.php/2009/01/28/fixing-c-static-and-global-variable-initialization/</guid>
		<description><![CDATA[Order of static and global variables initialization is a well-known uncontrolled phenomena. There is no way you can change it, variables will be initialized in an order the compiler is the sole to decide. The singleton fixes this problem by postponing the initialization at the first time the object is used. But then creation time [...]]]></description>
			<content:encoded><![CDATA[<p>Order of static and global variables initialization is a well-known uncontrolled phenomena. There is no way you can change it, variables will be initialized in an order the compiler is the sole to decide. The singleton fixes this problem by postponing the initialization at the first time the object is used. But then creation time is unknown and multi-threading issues may appear. This article propose a simple technique to force order of initialization.<br />
<span id="more-25"></span><br />
Let&#8217;s recall the C++ rule : Static member variables are initialized at last when the first instance of the class is created or when the first call to a static method is made. It also says that all globals are initialized before entering <code>main</code> function. Our technique will use those properties to order initialization.</p>
<p>The idea is pretty simple : create a list of initialization function, sort it and call all functions in order. While simple, there is some problems to solve. </p>
<p>How to create this list? Simply by using a global helper variable. Another C++&#8217;s rule states that a global variable should not be stripped if its constructor has side effect. Interesting! So there is the code that we use</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">struct</span> STATIC_DATA_FUNCTION_DECLARATOR
<span style="color: #008000;">&#123;</span>
    STATIC_DATA_FUNCTION_DECLARATOR<span style="color: #008000;">&#40;</span>
        STATIC_DATA_ENTRY <span style="color: #000040;">*</span> entry,
        <span style="color: #0000ff;">const</span> STATIC_DATA_FUNCTION function,
        <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span> name,
        <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span> predecessor_table,
        <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span> successor_table,
        <span style="color: #0000ff;">const</span> STATIC_DATA_FUNCTION_TYPE type
        <span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        STATIC_DATA<span style="color: #008080;">::</span><span style="color: #007788;">AddFunction</span><span style="color: #008000;">&#40;</span> entry, function, name, 
            predecessor_table, successor_table, type <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Then just create a global variable of this type :</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> initialize_function<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
STATIC_DATA_FUNCTION_DECLARATOR function_declarator<span style="color: #008000;">&#40;</span> 
    entry, <span style="color: #000040;">&amp;</span>initialize_function, <span style="color: #FF0000;">&quot;ClassX&quot;</span>, <span style="color: #FF0000;">&quot;ClassY&quot;</span>, <span style="color: #FF0000;">&quot;ClassZ&quot;</span>, 
    STATIC_DATA_FUNCTION_TYPE_Initializer <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>While the previous class helps us creating the list, it is a mess to use. You have to write a method, then declare the global helper object. The result is an ugly code that nobody wants to remember. Usually, when I get there, I think it&#8217;s time for our friends macros to take care of that.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">STATIC_DATA_InitializeType<span style="color: #008000;">&#40;</span> TypeX, <span style="color: #FF0000;">&quot;TypeY&quot;</span>, <span style="color: #FF0000;">&quot;TypeZ&quot;</span> <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">// Initialization code here</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
STATIC_DATA_FinalizeType<span style="color: #008000;">&#40;</span> TypeX, <span style="color: #FF0000;">&quot;&quot;</span>, <span style="color: #FF0000;">&quot;&quot;</span> <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">// Finalization code here</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>This code is preprocessed to :</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> TypeX_InitializeType<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">void</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
STATIC_DATA_FUNCTION_DECLARATOR TypeX_Initializer<span style="color: #008000;">&#40;</span> 
    <span style="color: #000040;">&amp;</span>STATIC_DATA_HELPER<span style="color: #000080;">&lt;</span>TypeX<span style="color: #000080;">&gt;</span><span style="color: #008080;">::</span><span style="color: #007788;">Entry</span>, <span style="color: #000040;">&amp;</span>TypeX_InitializeType, 
    <span style="color: #FF0000;">&quot;TypeX&quot;</span>, <span style="color: #FF0000;">&quot;TypeY&quot;</span>, <span style="color: #FF0000;">&quot;TypeZ&quot;</span>, STATIC_DATA_FUNCTION_TYPE_Initializer <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> 
&nbsp;
<span style="color: #0000ff;">void</span> TypeX_InitializeType<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">void</span> <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">// Initialization code here</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> TypeX_FinalizeType<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">void</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
STATIC_DATA_FUNCTION_DECLARATOR TypeX_Finalizer<span style="color: #008000;">&#40;</span> 
    <span style="color: #000040;">&amp;</span>STATIC_DATA_HELPER<span style="color: #000080;">&lt;</span>TypeX<span style="color: #000080;">&gt;</span><span style="color: #008080;">::</span><span style="color: #007788;">Entry</span>, <span style="color: #000040;">&amp;</span>TypeX_FinalizeType, 
    <span style="color: #FF0000;">&quot;TypeX&quot;</span>, <span style="color: #FF0000;">&quot;&quot;</span>,<span style="color: #FF0000;">&quot;&quot;</span>, STATIC_DATA_FUNCTION_TYPE_Finalizer <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> 
&nbsp;
<span style="color: #0000ff;">void</span> TypeX_FinalizeType<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">void</span> <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">// Finalization code here</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>There is another little trick there. To ensure there is only one node per type (the node stores both the initialization and finalization functions), a template class that just defines one static variable is used:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span> <span style="color: #0000ff;">class</span> _TYPE_ <span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">struct</span> STATIC_DATA_HELPER
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">static</span> STATIC_DATA_ENTRY 
        Entry<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span> <span style="color: #0000ff;">class</span> _TYPE_ <span style="color: #000080;">&gt;</span>
STATIC_DATA_ENTRY STATIC_DATA_HELPER<span style="color: #000080;">&lt;</span>_TYPE_<span style="color: #000080;">&gt;</span><span style="color: #008080;">::</span><span style="color: #007788;">Entry</span><span style="color: #008080;">;</span></pre></div></div>

<p>Inside <code>STATIC_DATA::AddFunction</code>, the entry is appended to the current list. So, if C++ rules are followed, when the program arrives in the <code>main</code> function, all the global helpers are initialized and the list must be complete. From there we call the function that will order the list and we call the initializer. Before exiting, we call the finalizers in reverse order.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> argument_table<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span>, <span style="color: #0000ff;">int</span> argument_count <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    STATIC_DATA<span style="color: #008080;">::</span><span style="color: #007788;">CallInitializers</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">// Some usefull code</span>
&nbsp;
    STATIC_DATA<span style="color: #008080;">::</span><span style="color: #007788;">CallFinalizers</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The ordering criteria is simply the text that is passed in the macro. Several types might be passed. The second text contains successors of the initialization method.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">STATIC_DATA_InitializeClass<span style="color: #008000;">&#40;</span> SCRIPT, <span style="color: #FF0000;">&quot;MEMORY FILESYSTEM&quot;</span>, <span style="color: #FF0000;">&quot;CONFIGURATION_SCRIPT&quot;</span> <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>I&#8217;m not covering all aspects of the code, but you can find it with <a href="http://www.fishingcactus.com/blog/static.rar">this working example</a>. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.fishingcactus.com/index.php/2009/01/28/fixing-c-static-and-global-variable-initialization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
