<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Arkaitzj's Blog</title>
	<atom:link href="http://arkaitzj.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://arkaitzj.wordpress.com</link>
	<description>Historias de Saladino</description>
	<lastBuildDate>Wed, 18 Jan 2012 12:04:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='arkaitzj.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Arkaitzj's Blog</title>
		<link>http://arkaitzj.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://arkaitzj.wordpress.com/osd.xml" title="Arkaitzj&#039;s Blog" />
	<atom:link rel='hub' href='http://arkaitzj.wordpress.com/?pushpress=hub'/>
		<item>
		<title>VNC in your browser through WebSockets, handled by Gevent</title>
		<link>http://arkaitzj.wordpress.com/2011/11/12/vnc-in-your-browser-through-websockets-handled-by-gevent/</link>
		<comments>http://arkaitzj.wordpress.com/2011/11/12/vnc-in-your-browser-through-websockets-handled-by-gevent/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 15:36:17 +0000</pubDate>
		<dc:creator>Arkaitz Jimenez</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[gevent]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[vnc]]></category>
		<category><![CDATA[websockets]]></category>

		<guid isPermaLink="false">http://arkaitzj.wordpress.com/?p=316</guid>
		<description><![CDATA[Reading on websockets the other day I ended in this article about websockets and vnc and it draw my attention immediately over the showmethedesktop project. Now, given my interest on async servers and my recent interest on their implementation on python along with the rustiness of my perl I decided to try a reimplementation on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=316&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<span style="text-align:center; display: block;"><a href="http://arkaitzj.wordpress.com/2011/11/12/vnc-in-your-browser-through-websockets-handled-by-gevent/"><img src="http://img.youtube.com/vi/_6J2PjBHqA4/2.jpg" alt="" /></a></span>
<p>Reading on websockets the other day I ended in <a href="http://showmetheco.de/articles/2010/11/technical-details-on-implementing-a-websocket-vnc-client.html">this article about websockets and vnc</a> and it draw my attention immediately over the <a href="https://github.com/vti/showmethedesktop" target="_blank">showmethedesktop</a> project.</p>
<p>Now, given my interest on async servers and my recent interest on their implementation on python along with the rustiness of my perl I decided to try a reimplementation on async python as a way to introduce me to the gevent framework.</p>
<h3>First impressions</h3>
<ul>
<li>It is actually feasible to draw a whole screen using just Javascript through canvas and (put/get)ImageData</li>
<li>Some browsers are remarkable faster than others doing this, chrome 15 has a 800&#215;600 draw time of 0-1 msec while Firefox 7 has about 5-13 msec draw time</li>
<li>It is perfectly usable unless you want to play videos or something like that</li>
</ul>
<h3>Project</h3>
<p>Available in <a href="https://github.com/arkaitzj/wsvnc">github</a>, comments and patches are welcome! still in development though.</p>
<h3>How did I do it</h3>
<p>Very quickly actually, thanks to <strong>python</strong> and <strong>gevent</strong>, and specially thanks to other projects I took and adapted code from, such as <a href="https://github.com/vti/showmethedesktop" target="_blank">showmethedesktop</a>, <a href="http://code.google.com/p/python-vnc-viewer/" target="_blank">python-vnc-viewer </a>and <a href="http://www.gelens.org/code/gevent-websocket/" target="_blank">gevent-websocket</a>.</p>
<ul>
<li>Most of the html+javascript is just copied from showmethedesktop with some adaptations of my own</li>
<li>I forked <a href="https://bitbucket.org/arkaitzj/gevent-websocket" target="_blank">gevent-websocket on bitbucket </a>and implemented the new hybi WS protocol on it, it is actually the only thing that current firefox and chrome speak so there was no option there, I also introduced some other small changes</li>
<li>I copied all the rfb(Remote Frame Buffer, VNC protocol) implementation from python-vnc-viewer and then removed the twisted dependency and adapted everything to work on gevent.</li>
<li>Finally thanks to gevent I created the &#8220;main&#8221; of my app, really just a gevent app</li>
</ul>
<h3>Issues</h3>
<p>Gevent and greenlet have some kind of incompatibility on python 2.7, requirements.txt had to include this version <code>http://bitbucket.org/snaury/greenlet/get/tip.zip#egg=greenlet</code></p>
<h3>Howto</h3>
<p><code>git clone git://github.com/arkaitzj/wsvnc.git &amp;&amp;<br />
cd wsvnc &amp;&amp;<br />
virtualenv --no-site-packages sandbox &amp;&amp;<br />
sandbox/bin/pip install -r requirements.txt &amp;&amp;<br />
sandbox/bin/python wsvnc.py<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/arkaitzj.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/arkaitzj.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/arkaitzj.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/arkaitzj.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/arkaitzj.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/arkaitzj.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/arkaitzj.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/arkaitzj.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/arkaitzj.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/arkaitzj.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/arkaitzj.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/arkaitzj.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/arkaitzj.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/arkaitzj.wordpress.com/316/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=316&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://arkaitzj.wordpress.com/2011/11/12/vnc-in-your-browser-through-websockets-handled-by-gevent/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b13a3e168d85c7f7f45ae1e54dc9db57?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Arkaitz Jimenez</media:title>
		</media:content>
	</item>
		<item>
		<title>Linux, add user to a group without logout</title>
		<link>http://arkaitzj.wordpress.com/2010/03/08/linux-add-user-to-a-group-without-logout/</link>
		<comments>http://arkaitzj.wordpress.com/2010/03/08/linux-add-user-to-a-group-without-logout/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 16:18:14 +0000</pubDate>
		<dc:creator>Arkaitz Jimenez</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[group]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[logout]]></category>
		<category><![CDATA[newgrp]]></category>
		<category><![CDATA[permissions]]></category>

		<guid isPermaLink="false">http://arkaitzj.wordpress.com/?p=293</guid>
		<description><![CDATA[We often find that we need to add ourselves to a given group to access a resource. Like, we need to access the cd reader and only people in the cdrom group can access it. Easy stuff, we just use sudo or su to get permissions and we do adduser my_user cdrom to add ourselves [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=293&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We often find that we need to add ourselves to a given group to access a resource.<br />
Like, we need to access the cd reader and only people in the <em>cdrom</em> group can access it. Easy stuff, we just use <em>sudo</em> or <em>su</em> to get permissions and we do <em>adduser my_user cdrom</em> to add ourselves to the <em>cdrom</em>group.</p>
<blockquote><p>#adduser my_user cdrom</p></blockquote>
<p>But this is not end of story. In order to get effective group permissions we need to logout and login again in the system for our group permissions to be refereshed, which is literaly a pain in the ass sometimes.</p>
<p>There is a quick trick that will save our time here, just do:</p>
<blockquote><p>$newgrp cdrom</p></blockquote>
<p>If we have been added to the group <em>newgrp</em> will give us instantly group permissions for the given group.<br />
For mor info on the subject:</p>
<blockquote><p>$man newgrp</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/arkaitzj.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/arkaitzj.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/arkaitzj.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/arkaitzj.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/arkaitzj.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/arkaitzj.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/arkaitzj.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/arkaitzj.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/arkaitzj.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/arkaitzj.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/arkaitzj.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/arkaitzj.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/arkaitzj.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/arkaitzj.wordpress.com/293/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=293&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://arkaitzj.wordpress.com/2010/03/08/linux-add-user-to-a-group-without-logout/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b13a3e168d85c7f7f45ae1e54dc9db57?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Arkaitz Jimenez</media:title>
		</media:content>
	</item>
		<item>
		<title>C++ tuples, a quick overview</title>
		<link>http://arkaitzj.wordpress.com/2009/11/20/c-tuples-a-quick-overview/</link>
		<comments>http://arkaitzj.wordpress.com/2009/11/20/c-tuples-a-quick-overview/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 15:00:52 +0000</pubDate>
		<dc:creator>Arkaitz Jimenez</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[g++]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[make_tuple]]></category>
		<category><![CDATA[tie]]></category>
		<category><![CDATA[tuple]]></category>

		<guid isPermaLink="false">http://arkaitzj.wordpress.com/?p=264</guid>
		<description><![CDATA[Ok, c++ tuples, here is quick and dirty: At the first look, returning several values from a function/method in C++ may look awkward and contrary to the C++ way, being more usual in languages like python or perl. However the fact is that template metaprogramming gives us the ability to do such good tricks and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=264&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ok, c++ tuples, here is quick and dirty:<br />
<pre class="brush: cpp;">
// g++ 4.1
#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;tr1/tuple&gt;
using std::tr1::tuple;
using std::tr1::tie;
using std::tr1::make_tuple;

tuple&lt;std::string,int&gt; parse_url(const std::string&amp; url){
    return make_tuple(&quot;127.0.0.1&quot;,9000); //Cheat for parsing
}
int main(){
    std::string host;
    int port;
    tie(host,port) = parse_url(&quot;127.0.0.1:9000&quot;);
    std::cout &lt;&lt; &quot;Host: &quot;&lt;&lt;host&lt;&lt; &quot;:&quot;&lt;&lt;port&lt;&lt;&quot;\n&quot;;
}
</pre></p>
<p>At the first look, returning several values from a function/method in C++ may look awkward and contrary to the C++ way, being more usual in languages like python or perl.<br />
However the fact is that template metaprogramming gives us the ability to do such good tricks and renders the rest for us in compile-time. This tuple templates are part of the TR1 and thats why we need to include them from &lt;tr1/tuple&gt; and use them from std::tr1 namespace, but they&#8217;ll be part of the next standard c++0x. </p>
<p>The logic behind the metaprogramming is simple, by the time you compile a tuple the compiler knows perfectly the size of the new type because you supply the template parameters.</p>
<p><strong>tie()</strong> for example is a template that gets the given parameters and put references to them in an lvalue obj that can be assigned to, so its a painless way of getting results from a tuple_returning method.<br />
<strong>make_tuple()</strong> goes the same way but creates a new tuple with copies of the provided parameters, so it is a quick way of creating tuples of any size, its like the current <em>make_pair()</em> but for tuples.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/arkaitzj.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/arkaitzj.wordpress.com/264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/arkaitzj.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/arkaitzj.wordpress.com/264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/arkaitzj.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/arkaitzj.wordpress.com/264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/arkaitzj.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/arkaitzj.wordpress.com/264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/arkaitzj.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/arkaitzj.wordpress.com/264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/arkaitzj.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/arkaitzj.wordpress.com/264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/arkaitzj.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/arkaitzj.wordpress.com/264/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=264&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://arkaitzj.wordpress.com/2009/11/20/c-tuples-a-quick-overview/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b13a3e168d85c7f7f45ae1e54dc9db57?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Arkaitz Jimenez</media:title>
		</media:content>
	</item>
		<item>
		<title>Widen wordpress.com Contempt theme</title>
		<link>http://arkaitzj.wordpress.com/2009/11/08/widen-wordpress-com-contempt-theme/</link>
		<comments>http://arkaitzj.wordpress.com/2009/11/08/widen-wordpress-com-contempt-theme/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 22:35:47 +0000</pubDate>
		<dc:creator>Arkaitz Jimenez</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[contempt]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[wider]]></category>
		<category><![CDATA[wordpress.com]]></category>

		<guid isPermaLink="false">http://arkaitzj.wordpress.com/?p=243</guid>
		<description><![CDATA[Just buy the &#8220;edit css&#8221; improvement and add the next lines to your css to get a wider theme, you&#8217;ll lose the shadows on the sides though. EDIT: Thanks to Ivan Zahariev for the tip on keeping the side shadows<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=243&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just buy the &#8220;edit css&#8221; improvement and add the next lines to your css to get a wider theme, you&#8217;ll lose the shadows on the sides though.<br />
<pre class="brush: css;">
#pagebar { width:955px; }
#page { width:955px; }
#content { width:700px; }
#sidebar { margin:-60px 0 0 750px; }
#headerimg {
background-image:url('http://s2.wordpress.com/wp-content/themes/pub/contempt/images/blue_flower/head.jpg');
background-repeat:repeat-x;
}
#footer {width:955px; }
</pre><br />
<strong>EDIT:</strong> Thanks to Ivan Zahariev for the <a href="http://blog.famzah.net/2009/11/20/make-wordpress-com-contempt-theme-layout-wider">tip</a> on keeping the side shadows</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/arkaitzj.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/arkaitzj.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/arkaitzj.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/arkaitzj.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/arkaitzj.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/arkaitzj.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/arkaitzj.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/arkaitzj.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/arkaitzj.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/arkaitzj.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/arkaitzj.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/arkaitzj.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/arkaitzj.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/arkaitzj.wordpress.com/243/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=243&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://arkaitzj.wordpress.com/2009/11/08/widen-wordpress-com-contempt-theme/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b13a3e168d85c7f7f45ae1e54dc9db57?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Arkaitz Jimenez</media:title>
		</media:content>
	</item>
		<item>
		<title>Static locals and threadsafety in g++</title>
		<link>http://arkaitzj.wordpress.com/2009/11/07/static-locals-and-threadsafety-in-g/</link>
		<comments>http://arkaitzj.wordpress.com/2009/11/07/static-locals-and-threadsafety-in-g/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 19:38:51 +0000</pubDate>
		<dc:creator>Arkaitz Jimenez</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[meyers singleton]]></category>
		<category><![CDATA[singleton]]></category>
		<category><![CDATA[static local]]></category>
		<category><![CDATA[threadsafe]]></category>
		<category><![CDATA[__cxa_guard_acquire]]></category>

		<guid isPermaLink="false">http://arkaitzj.wordpress.com/?p=156</guid>
		<description><![CDATA[Often when looking in the internet for implementations of some patterns in C++ we come across the well-known Meyers singleton, which is basically the next code: This essentially reserves static memory for the size of the instance and executes the class constructor during the first call to getInstance(), this of course occurs only if we [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=156&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Often when looking in the internet for implementations of some patterns in C++ we come across the well-known <em>Meyers singleton</em>, which is basically the next code:<br />
<pre class="brush: cpp;">
class Singleton{   
    Singleton(){
        // Thread-unsafe code
    }
    static Singleton* getInstance(){
        static Singleton instance;
        return &amp;instance;
    }
};
</pre></p>
<p>This essentially reserves static memory for the size of the instance and executes the class constructor <strong>during the first call to getInstance()</strong>, this of course occurs only if we are dealing with a non-<a href="http://en.wikipedia.org/wiki/Plain_old_data_structures">POD</a> object.</p>
<p>The problem here is that we might run in problems if we get inside <strong>getInstance</strong> with 2 threads at the same time <strong>for the first time</strong>. Obviously the constructor is not thread-safe <em>per se</em>.</p>
<p>However, GCCs g++ gives us a help here and protects every local static variable <strong>construction</strong> with thread-safe guards, <em>__cxa_guard_acquire</em> and <em>__cxa_guard_release</em> do the job here protecting the constructor. Note that this only happens with local statics as global static construction occurs before any function of the translation unit gets executed.</p>
<p>Differences are obvious if we take a look at the generated code, PODs are just data so no construction is needed, non-PODs are properly protected</p>
<p>POD type, function body highlighted:<br />
<pre class="brush: cpp; highlight: [3,4];">
class pod_class {    public: 
        static pod_class* instance(){ 
            static pod_class once; 
            return &amp;once;
        }};
int main(){ return (int)pod_class::instance; }
</pre><br />
<pre class="brush: plain; highlight: [4];">
080483fd &lt;_ZN9pod_class8instanceEv&gt;:
 80483fd:       55                push   %ebp
 80483fe:       89 e5             mov    %esp,%ebp
 8048400:       b8 f8 95 04 08    mov    $0x80495f8,%eax
 8048405:       5d                pop    %ebp
 8048406:       c3                ret          
</pre><br />
Non-POD type, <strong>class constructor</strong> and function body higlighted:<br />
<span id="more-156"></span><br />
<pre class="brush: cpp; highlight: [2,4];">
class nonpod_class {    public:
        nonpod_class(){}
        static nonpod_class* instance(){
            static nonpod_class once; return &amp;once;
        }};
int main(){ return (int)nonpod_class::instance; }
</pre><br />
<pre class="brush: plain; highlight: [5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]; wrap-lines: false;">
080484b3 &lt;_ZN12nonpod_class8instanceEv&gt;:
 80484b3:  55                    push   %ebp
 80484b4:  89 e5                 mov    %esp,%ebp
 80484b6:  83 ec 08              sub    $0x8,%esp
 80484b9:  b8 f0 96 04 08        mov    $0x80496f0,%eax
 80484be:  0f b6 00              movzbl (%eax),%eax
 80484c1:  84 c0                 test   %al,%al
 80484c3:  75 2d                 jne    80484f2 &lt;_ZN12nonpod_class8instanceEv+0x3f&gt;
 80484c5:  c7 04 24 f0 96 04 08  movl   $0x80496f0,(%esp)
 80484cc:  e8 c7 fe ff ff        call   8048398 &lt;__cxa_guard_acquire@plt&gt;
 80484d1:  85 c0                 test   %eax,%eax
 80484d3:  0f 95 c0              setne  %al
 80484d6:  84 c0                 test   %al,%al
 80484d8:  74 18                 je     80484f2 &lt;_ZN12nonpod_class8instanceEv+0x3f&gt;
 80484da:  c7 04 24 f8 96 04 08  movl   $0x80496f8,(%esp)
 80484e1:  e8 c8 ff ff ff        call   80484ae &lt;_ZN12nonpod_classC1Ev&gt;
 80484e6:  c7 04 24 f0 96 04 08  movl   $0x80496f0,(%esp)
 80484ed:  e8 d6 fe ff ff        call   80483c8 &lt;__cxa_guard_release@plt&gt;
 80484f2:  b8 f8 96 04 08        mov    $0x80496f8,%eax
 80484f7:  c9                    leave         
 80484f8:  c3                    ret           
</pre></p>
<p>This behaviour can be avoided by using -fno-threadsafe-statics in the g++s commandline.</p>
<p><strong>EDIT:</strong> Thanks to Tom in the comment below I updated the post with the involved code_comment from gcc project<br />
<a href="http://gcc.gnu.org/viewcvs/branches/gcc-4_2-branch/gcc/cp/decl.c?view=markup&amp;pathrev=129388">http://gcc.gnu.org/viewcvs/branches/gcc-4_2-branch/gcc/cp/decl.c?view=markup&amp;pathrev=129388</a></p>
<p><pre class="brush: cpp;">
/* Emit code to perform this initialization but once. This code looks like:
static guard;
if (!guard.first_byte) {
    if (__cxa_guard_acquire (&amp;guard)) {
        bool flag = false;
        try {
            // Do initialization.
            flag = true; __cxa_guard_release (&amp;guard);
            // Register variable for destruction at end of program.
        } catch {
            if (!flag) __cxa_guard_abort (&amp;guard);
        }
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/arkaitzj.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/arkaitzj.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/arkaitzj.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/arkaitzj.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/arkaitzj.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/arkaitzj.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/arkaitzj.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/arkaitzj.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/arkaitzj.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/arkaitzj.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/arkaitzj.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/arkaitzj.wordpress.com/156/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/arkaitzj.wordpress.com/156/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/arkaitzj.wordpress.com/156/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=156&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://arkaitzj.wordpress.com/2009/11/07/static-locals-and-threadsafety-in-g/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b13a3e168d85c7f7f45ae1e54dc9db57?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Arkaitz Jimenez</media:title>
		</media:content>
	</item>
		<item>
		<title>C++0x cool features: Lambda function</title>
		<link>http://arkaitzj.wordpress.com/2009/09/18/c0x-cool-features-lambda-functions/</link>
		<comments>http://arkaitzj.wordpress.com/2009/09/18/c0x-cool-features-lambda-functions/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 18:22:31 +0000</pubDate>
		<dc:creator>Arkaitz Jimenez</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[c++0x]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[lambda]]></category>

		<guid isPermaLink="false">http://arkaitzj.wordpress.com/?p=113</guid>
		<description><![CDATA[Have you heard that a new c++ draft is coming soon? It&#8217;s called c++0x for the moment and includes some new cool features. A good description of the new features. Basics I&#8217;ve been recently playing around with lambda function support and looks pretty stable in the gcc compiler. I haven&#8217;t tried but I read that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=113&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Have you heard that a new c++ draft is coming soon? It&#8217;s called c++0x for the moment and includes some new cool features.<br />
A <a href="http://en.wikipedia.org/wiki/C%2B%2B0x">good description</a> of the new features.</p>
<h3>Basics</h3>
<p>I&#8217;ve been recently playing around with lambda function support and looks pretty stable in the gcc compiler. I haven&#8217;t tried but I read that VC2010 has lambda support as well.</p>
<p>It gives support for in-place anonymous function definitions with context access, which basically helps us in a lot of situations, for example, if a given function, say <strong>wait_5minutes_call(callback_function)</strong>, requires a callback we could easily do:<br />
<pre class="brush: cpp; gutter: false; wrap-lines: false;">
wait_5minutes_call( [ ](){ std::cout &lt;&lt; &quot;Callback called\n&quot;;} );
</pre><br />
<strong>And thats all!! cool isn&#8217;t it?</strong><br />
A more complete example:<br />
<pre class="brush: cpp; wrap-lines: false;">
#include &lt;iostream&gt;
#include &lt;functional&gt;
#include &lt;algorithm&gt;
void print_function(int size, std::function funct){
    std::cout &lt;&lt; funct(size) &lt;&lt; std::endl;
}
int main(int argc, char* argv[])
{
    auto myfnc = [](int size){return size*size;};
    print_function(10,myfnc);
    return 0;
}
</pre><br />
The syntax is:<br />
<span id="more-113"></span><br />
<pre class="brush: cpp; gutter: false; wrap-lines: false;">
[howtogetcontext](ptype parameter){body} // implicit return type resolution
[howtogetcontext](ptype parameter) -&gt;returntype {body} // explicit return type resolution
</pre><br />
howtogetcontext specifies how we get the context, it can be <em>[&amp;]</em> by ref or <em>[=]</em> by value(a copy), or we can say <em>[&amp;,variablename]</em> for get everything by ref except variablename.</p>
<h3>What is the context?</h3>
<p>The context are the variables scoped in the place we define the lambda function.<br />
Yes, we can access those variables even if we pass the lambda function far away of the current scope definition. Of course if any of those variables went out-of-scope or was freed and we refer to them by reference we&#8217;ll get a big crash, there&#8217;s no magic <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .<br />
We can access everything that is in scope on definition, locals, even <em>this</em> pointer if the function was defined inside an object method, actually, any method defined inside an class method is a <em>friend</em> of the class.</p>
<h3>Ok, how do I get those cool lambda functions?</h3>
<p>Easy.<br />
We need to download the gcc development branch for lambda, as the trunk doesn&#8217;t have lambda support.</p>
<pre>svn co svn://gcc.gnu.org/svn/gcc/branches/cxx0x-lambdas-branch gcc-lambda
mkdir build
cd build
# Compilation can take several hours, depends on your machine
../gcc-lambda/configure --program-prefix=lambda --disable-libgcj --enable-languages=c++ --disable-werror
make -j3
make install</pre>
<p>Now you have a lambdag++ binary in your system which you can use to compile c++ code with lambdas just like this:</p>
<pre>
lambdag++ --std=g++c0x main.cpp -o main
</pre>
<p>Don&#8217;t forget the <strong>&#8211;std=c++0x</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/arkaitzj.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/arkaitzj.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/arkaitzj.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/arkaitzj.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/arkaitzj.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/arkaitzj.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/arkaitzj.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/arkaitzj.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/arkaitzj.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/arkaitzj.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/arkaitzj.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/arkaitzj.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/arkaitzj.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/arkaitzj.wordpress.com/113/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=113&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://arkaitzj.wordpress.com/2009/09/18/c0x-cool-features-lambda-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b13a3e168d85c7f7f45ae1e54dc9db57?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Arkaitz Jimenez</media:title>
		</media:content>
	</item>
		<item>
		<title>Receiving notifications for new stackoverflow c++ questions</title>
		<link>http://arkaitzj.wordpress.com/2009/07/30/receiving-notifications-for-new-stackoverflow-c-questions/</link>
		<comments>http://arkaitzj.wordpress.com/2009/07/30/receiving-notifications-for-new-stackoverflow-c-questions/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 11:33:06 +0000</pubDate>
		<dc:creator>Arkaitz Jimenez</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[stackoverflow]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://arkaitzj.wordpress.com/?p=98</guid>
		<description><![CDATA[Just created a quick perl script for reading the c++ question rss feed and used notify-send to get the notifications in the desktop. You need libnotify-bin and notification-daemon installed in your debian/ubuntu<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=98&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just created a quick perl script for reading the c++ question rss feed and used notify-send to get the notifications in the desktop.<br />
You need libnotify-bin and notification-daemon installed in your debian/ubuntu<br />
<pre class="brush: perl;">
#!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;

my $url=&quot;http://stackoverflow.com/feeds/tag/c%2b%2b&quot;;
my $max = 5;

my %newshash;
while(1){

    my @news;
    my @titles;
    my @urls;

    my $feed = get $url;
    if(not $feed){
        my $exec = &quot;notify-send -t 10000 \&quot;Stackoverflow C++\&quot; \&quot;Can't reach $url\&quot;&quot;;
        system($exec);
        sleep(600);
        next;
    }
    @urls = $feed =~ m/&lt;id&gt;(.+)&lt;\/id&gt;/g;
    @titles = $feed =~ m/&lt;title type=&quot;text&quot;&gt;(.+)&lt;\/title&gt;/g;
    for( my $i=0; $i&lt;(scalar @titles) ; $i++){
        push(@news,[$titles[$i],$urls[$i]]);
    }
    shift(@news);

    my $printed = 0;
    for my $new (@news){
        my($id) = $new-&gt;[1] =~ m/questions\/([0-9]+)\// or print &quot;Faulty id in $new-&gt;[1]&quot;;

        if( not exists($newshash{$id})){
            $newshash{$id} = $new-[1];
            if($printed&lt;$max){
                my $exec = &quot;notify-send -t 10000 'Stackoverflow C++'  '&lt;a href=\&quot;&quot;.$new-&gt;[1].&quot;\&quot;&gt;&quot;.$new-&gt;[0].&quot;&lt;/a&gt;'&quot;;
                system($exec);
                print $new-&gt;[0] . &quot;\n&quot;;
            }
            $printed++;
       }
    }
    sleep 300;
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/arkaitzj.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/arkaitzj.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/arkaitzj.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/arkaitzj.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/arkaitzj.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/arkaitzj.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/arkaitzj.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/arkaitzj.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/arkaitzj.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/arkaitzj.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/arkaitzj.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/arkaitzj.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/arkaitzj.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/arkaitzj.wordpress.com/98/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=98&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://arkaitzj.wordpress.com/2009/07/30/receiving-notifications-for-new-stackoverflow-c-questions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b13a3e168d85c7f7f45ae1e54dc9db57?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Arkaitz Jimenez</media:title>
		</media:content>
	</item>
		<item>
		<title>localtime is not thread safe</title>
		<link>http://arkaitzj.wordpress.com/2009/07/30/localtime-is-not-thread-safe/</link>
		<comments>http://arkaitzj.wordpress.com/2009/07/30/localtime-is-not-thread-safe/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 08:56:48 +0000</pubDate>
		<dc:creator>Arkaitz Jimenez</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[glibc]]></category>
		<category><![CDATA[libc]]></category>
		<category><![CDATA[localtime]]></category>
		<category><![CDATA[multithread]]></category>
		<category><![CDATA[threadsafe]]></category>

		<guid isPermaLink="false">http://arkaitzj.wordpress.com/?p=90</guid>
		<description><![CDATA[Thats right, current glibc&#8217;s implementation of localtime function is not thread-safe, instead we have localtime_r available which offers the same functionality but it is reentrant. Here is why glibc/time/localtime.c struct tm _tmbuf; /* Return the `struct tm' representation of *T in local time, using *TP to store the result. */ struct tm * __localtime_r (t, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=90&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Thats right, current glibc&#8217;s implementation of localtime function is not thread-safe, instead we have localtime_r available which offers the same functionality but it is reentrant.<br />
Here is why</p>
<li><b><i>glibc/time/localtime.c</i></b></li>
<pre>
struct tm _tmbuf;
/* Return the `struct tm' representation of *T in local time,
   using *TP to store the result.  */
struct tm *
__localtime_r (t, tp)
     const time_t *t;
     struct tm *tp;
{
  return __tz_convert (t, 1, tp);
}
weak_alias (__localtime_r, localtime_r)

/* Return the `struct tm' representation of *T in local time.  */
struct tm *
localtime (t)
     const time_t *t;
{
  return __tz_convert (t, 1, &amp;_tmbuf);
}
libc_hidden_def (localtime)
</pre>
<p><span id="more-90"></span></p>
<p>The localtime representation is returned in a chunk of memory than in the case of <em>localtime_r</em> is given by the user but in the case of the standard <em>localtime</em> <strong>every call returns the result in the same memory chunk</strong>, currently it uses the file scoped variable <strong>_tmbuf</strong> in localtime compilation unit.<br />
So simultaneous calls to the <em>localtime</em> will produce non-desired results in every real concurrency scenario.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/arkaitzj.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/arkaitzj.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/arkaitzj.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/arkaitzj.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/arkaitzj.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/arkaitzj.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/arkaitzj.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/arkaitzj.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/arkaitzj.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/arkaitzj.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/arkaitzj.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/arkaitzj.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/arkaitzj.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/arkaitzj.wordpress.com/90/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=90&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://arkaitzj.wordpress.com/2009/07/30/localtime-is-not-thread-safe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b13a3e168d85c7f7f45ae1e54dc9db57?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Arkaitz Jimenez</media:title>
		</media:content>
	</item>
		<item>
		<title>Starting with PSP homebrew</title>
		<link>http://arkaitzj.wordpress.com/2009/07/19/starting-with-psp-homebrew/</link>
		<comments>http://arkaitzj.wordpress.com/2009/07/19/starting-with-psp-homebrew/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 20:42:23 +0000</pubDate>
		<dc:creator>Arkaitz Jimenez</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Computers]]></category>
		<category><![CDATA[homebrew]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[psp]]></category>
		<category><![CDATA[toolchain]]></category>

		<guid isPermaLink="false">http://arkaitzj.wordpress.com/?p=72</guid>
		<description><![CDATA[Host system: Debian GNU/Linux sid/testing x86 PSP: PSP Slim with a hacked 3.90M33-2 firmware Required tools and libs Prepare a place for the PSP development stuff: mkdir -p $HOME/lib/pspdev Make it available for your current session: echo -e "export PSPDEV=~/lib/pspdev\nexport PATH=\$PATH:\$PSPDEV/bin" &#62;&#62; $HOME/.bashrc bash Get and install the toolchain: svn co svn://svn.ps2dev.org/psp/trunk/psptoolchain cd psptoolchain ./toolchain.sh [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=72&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Host system: Debian GNU/Linux sid/testing x86<br />
PSP: PSP Slim with a hacked 3.90M33-2 firmware</p>
<h4>Required tools and libs</h4>
<p>Prepare a place for the PSP development stuff:</p>
<pre>mkdir -p $HOME/lib/pspdev</pre>
<p>Make it available for your current session:</p>
<pre>echo -e "export PSPDEV=~/lib/pspdev\nexport PATH=\$PATH:\$PSPDEV/bin" &gt;&gt; $HOME/.bashrc
bash</pre>
<p>Get and install the toolchain:</p>
<pre>svn co svn://svn.ps2dev.org/psp/trunk/psptoolchain
cd psptoolchain
./toolchain.sh</pre>
<p>It&#8217;ll probably ask for some develpment packages, just look for them in apt, install them and run the last step again.</p>
<p>Get and install psp libraries</p>
<pre>
svn co svn://svn.ps2dev.org/psp/trunk/psplibraries
cd psplibraries
./libraries.sh
</pre>
<p><em>Ok, requirements installed</em><br />
<span id="more-72"></span></p>
<h4>Hello world</h4>
<p>main.cpp<br />
<pre class="brush: cpp; wrap-lines: false;">
#include &lt;pspkernel.h&gt;
#include &lt;pspdebug.h&gt;

PSP_MODULE_INFO(&quot;Hello World&quot;, 0, 1, 1);

#define printf pspDebugScreenPrintf 

/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
          sceKernelExitGame();
          return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
          int cbid;

          cbid = sceKernelCreateCallback(&quot;Exit Callback&quot;, exit_callback, NULL);
          sceKernelRegisterExitCallback(cbid);

          sceKernelSleepThreadCB();

          return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
    int thid = 0;

    thid = sceKernelCreateThread(&quot;update_thread&quot;, CallbackThread, 0x11, 0xFA0, 0, 0);
    if(thid &amp;gt;= 0) {
        sceKernelStartThread(thid, 0, 0);
    }

    return thid;
}

int main() {
    pspDebugScreenInit();
    SetupCallbacks();
    printf(&quot;Hello World&quot;);
    sceKernelSleepThread();
    return 0;
}
</pre></p>
<p>Makefile</p>
<pre>
TARGET = hello
OBJS = main.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Hello World

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
</pre>
<p>Ok, now compile it</p>
<pre>
saladino@Zack:~/projects/pspstuff$ make
psp-g++ -I. -I/home/saladino/lib/pspdev/psp/sdk/include -O2 -G0 -Wall -I. -I/home/saladino/lib/pspdev/psp/sdk/include -O2 -G0 -Wall -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150   -c -o main.o main.cpp
psp-gcc -I. -I/home/saladino/lib/pspdev/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=150  -L. -L/home/saladino/lib/pspdev/psp/sdk/lib   main.o  -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o hello.elf
psp-fixup-imports hello.elf
mksfo 'Hello World' PARAM.SFO
psp-strip hello.elf -o hello_strip.elf
pack-pbp EBOOT.PBP PARAM.SFO NULL  \
		NULL NULL NULL  \
		NULL  hello_strip.elf NULL
[0]        408 bytes | PARAM.SFO
[1]          0 bytes | NULL
[2]          0 bytes | NULL
[3]          0 bytes | NULL
[4]          0 bytes | NULL
[5]          0 bytes | NULL
[6]      77508 bytes | hello_strip.elf
[7]          0 bytes | NULL
rm -f hello_strip.elf
</pre>
<p>That&#8217;s all, now copy it to the corresponding folder in your memory stick, in my case this was <em>psp/game380/helloworld/EBOOT.PBP</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/arkaitzj.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/arkaitzj.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/arkaitzj.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/arkaitzj.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/arkaitzj.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/arkaitzj.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/arkaitzj.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/arkaitzj.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/arkaitzj.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/arkaitzj.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/arkaitzj.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/arkaitzj.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/arkaitzj.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/arkaitzj.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=72&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://arkaitzj.wordpress.com/2009/07/19/starting-with-psp-homebrew/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b13a3e168d85c7f7f45ae1e54dc9db57?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Arkaitz Jimenez</media:title>
		</media:content>
	</item>
		<item>
		<title>How to use a CVS server from a git client</title>
		<link>http://arkaitzj.wordpress.com/2009/06/15/how-to-use-a-cvs-server-from-a-git-client/</link>
		<comments>http://arkaitzj.wordpress.com/2009/06/15/how-to-use-a-cvs-server-from-a-git-client/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 15:42:23 +0000</pubDate>
		<dc:creator>Arkaitz Jimenez</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[cvs]]></category>
		<category><![CDATA[cvsexportcommit]]></category>
		<category><![CDATA[cvsimport]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[scm]]></category>
		<category><![CDATA[vcs]]></category>

		<guid isPermaLink="false">http://arkaitzj.wordpress.com/?p=49</guid>
		<description><![CDATA[First Checkout We need 2 repos, one for git and one for cvs but we don&#8217;t touch cvs one ever repos/MODULENAME cvs/MODULENAME git cvsimport -d server:/path/to/cvs -C repo/MODULENAME -r cvs -k MODULENAME cvs checkout -d cvs/MODULENAME MODULENAME Create a new branch to work git checkout -b non-master-branch-name Tweaks for automatic updating modulename, cvs and the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=49&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>First Checkout</h2>
<ul>
<li> We need 2 repos, one for git and one for cvs but we don&#8217;t touch cvs one ever</li>
</ul>
<blockquote>
<ul>
<li>repos/MODULENAME</li>
<li>cvs/MODULENAME</li>
</ul>
</blockquote>
<p style="padding-left:30px;">
<pre>git cvsimport -d server:/path/to/cvs -C repo/MODULENAME -r cvs -k MODULENAME
cvs checkout -d cvs/MODULENAME MODULENAME</pre>
<h2>Create a new branch to work</h2>
<pre>git checkout -b non-master-branch-name</pre>
<h2>Tweaks for automatic updating</h2>
<p>modulename, cvs and the $CVSROOT contents</p>
<pre>git config cvsimport.module MODULENAME
git config cvsimport.r cvs
git config cvsimport.d server:/path/to/cvs</pre>
<h2>Updating the code</h2>
<pre>git checkout master
git cvsimport
git checkout non-master-branch-name
git rebase master</pre>
<h2>Use</h2>
<ul>
<li>Create another branch, DON&#8217;T WORK ON MASTER branch,use it only for updates, rebases and commits.</li>
<li> Steps:<br />
<span id="more-49"></span></p>
<ul>
<li> Modify the code in non-master branch and commit there</li>
<li> We may have several commits in our non-master branch, some of them we want them in master and others maybe not, we need to tell to cvsexportcommit from which commit to which commit we want to export, so lets say the master and non-master branchs were synced and that we commited a single commit to the non-master branch and we want it in the cvs</li>
<li> First we need its commit-id and the commit-id of the previous one</li>
<pre>arkaitzj@zack:~/repos/module$ git log  --pretty=oneline -n2
60e3c17262aa67adece8070e1b47e819353b778c Test improvements                           #Last commit
3ee1411a952b81ff70bcbf0219852b70cccd67f0    Softwaretest needed Makefiles added  #Previous commit, exists in both branches</pre>
</ul>
</li>
<li>Now we export to cvs the changes on those commit</li>
</ul>
<ul>
<li>-w parameter marks the path of the cvs checked out code, no need to touch it but needs to be there for cvsexportcommit</li>
<li> -u ensures the cvs repo is updated before diffs applied</li>
<li> -p makes diff reject dubious patches Remember to always update before exportcommit</li>
<li> -c if the patch was cleanly applied it is committed to cvs automatically</li>
<pre>arkaitzj@zack:~/repos/modulename$ git cvsexportcommit -w ../../cvs/modulename -u -p -c   3ee1411a952b81ff70bcbf0219852b7 60e3c17262aa67adece8070e1b47e</pre>
</ul>
<ul>
<li>Committed, next time we do a cvs import on master branch we&#8217;ll get the changes from the CVS server, but still we need an extra step</li>
<li>As cvsimport and cvsexportcommit don&#8217;t play well for the moment they don&#8217;t recognize each other commits, so once we&#8217;ve committed something from non-master branch we still have to do 3 things, remove the commit from non-master branch, cvsimport the last change to master branch and rebase non-master branch to master</li>
</ul>
<p><strong><em>Let 10 minutes pass from the cvsexportcommit to the cvsimport, if you don&#8217;t see your commit on master history after cvsimport wait a little more and cvsimport again</em></strong></p>
<pre>#non-master branch
git rebase -i HEAD~2 # Find the last commit(what we sent to CVS) and remove that line, this will erase that commit form history
#Checkout master branch and cvsimport
git checkout master
git cvsimport
#Now we have imported our commit from the CVS and it is valid history of the master branch, checkout non-master and rebase
git checkout non-master
git rebase master</pre>
<ul>
<li>Use this script, it&#8217;ll warn you on commits and you&#8217;ll know wich branch are you committing to. place it in DEST_DIRECTORY/.git/hooks/pre-commit</li>
</ul>
<pre>arkaitzj@zack:~/repos/module$ cat .git/hooks/pre-commit
#!/bin/bash
NC='\e[0m' # No Color
RED='\e[1;31m'
BRANCHNAME=$(git branch --no-color 2&gt; /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')

exec &lt; /dev/tty
echo -e "Committing to branch $RED$BRANCHNAME$NC. Commit (y/n): "
read response

if [ "$response" == "y" ]
then
       echo "Committing...."
       exit 0
else
       echo "Commit ABORTED"
       exit 1
fi</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/arkaitzj.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/arkaitzj.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/arkaitzj.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/arkaitzj.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/arkaitzj.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/arkaitzj.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/arkaitzj.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/arkaitzj.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/arkaitzj.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/arkaitzj.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/arkaitzj.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/arkaitzj.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/arkaitzj.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/arkaitzj.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=arkaitzj.wordpress.com&amp;blog=6776015&amp;post=49&amp;subd=arkaitzj&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://arkaitzj.wordpress.com/2009/06/15/how-to-use-a-cvs-server-from-a-git-client/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b13a3e168d85c7f7f45ae1e54dc9db57?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Arkaitz Jimenez</media:title>
		</media:content>
	</item>
	</channel>
</rss>
