<?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>Alex on Linux</title>
	<atom:link href="http://www.alexonlinux.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.alexonlinux.com</link>
	<description></description>
	<lastBuildDate>Thu, 22 Sep 2011 22:49:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>UML cheatsheet</title>
		<link>http://www.alexonlinux.com/uml-cheatsheet</link>
		<comments>http://www.alexonlinux.com/uml-cheatsheet#comments</comments>
		<pubDate>Mon, 19 Sep 2011 16:48:44 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code library]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[Programming Articles]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[Short articles]]></category>
		<category><![CDATA[cheatsheet]]></category>
		<category><![CDATA[class diagram]]></category>
		<category><![CDATA[drawing]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[UML]]></category>
		<category><![CDATA[uml diagram]]></category>
		<category><![CDATA[uml reference]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1945</guid>
		<description><![CDATA[Every once in awhile, I have to draw a UML diagram. I rarely do serious designs with UML, however sometimes I do need to depict some piece of code in a diagram and UML seems to be the best notation around. Unfortunately, various sources of information on UML tend to over-complicate things. I am not software architect [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Every once in awhile, I have to draw a UML diagram. I rarely do serious designs with UML, however sometimes I do need to depict some piece of code in a diagram and UML seems to be the best notation around.</p>
<p>Unfortunately, various sources of information on UML tend to over-complicate things. I am not software architect and drawing UMLs is not my job. So my UML skills are poor by definition. Moreover, I am happy with this situation and don&#8217;t see it changing in the future (even if I get promoted <img src='http://www.alexonlinux.com/wp-content/plugins/smilies-themer/modern/wink.gif' alt=';-)' class='wp-smiley' /> ).</p>
<p>So from time to time I need a simple UML reference card. Simple search finds references <a href="http://www.holub.com/goodies/uml/" onclick="return TrackClick('http%3A%2F%2Fwww.holub.com%2Fgoodies%2Fuml%2F','like+this+one')">like this one</a>, which are excellent if you are serious about UML, and I am not.</p>
<p>Eventually, I decided to write a short UML class diagram reference card for myself. I hope you will enjoy it as well.<br />
<span id="more-1945"></span></p>
<h2>Inheritance</h2>
<p><a href="http://www.alexonlinux.com/wp-content/uploads/2011/09/child_inherits_from_parent.png" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2011%2F09%2Fchild_inherits_from_parent.png','child_inherits_from_parent')"><img class="size-full wp-image-1952 aligncenter" title="child_inherits_from_parent" src="http://www.alexonlinux.com/wp-content/uploads/2011/09/child_inherits_from_parent.png" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2011%2F09%2Fchild_inherits_from_parent.png','child_inherits_from_parent')" alt="" width="456" height="103" /></a></p>
<p>So, this is how classes inherit one from another. Here <em>Child class</em> inherits from <em>Parent Class</em>.</p>
<h2>Use</h2>
<p><a href="http://www.alexonlinux.com/wp-content/uploads/2011/09/user_uses_resource.png" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2011%2F09%2Fuser_uses_resource.png','user_uses_resource')"><img class="size-full wp-image-1953 aligncenter" title="user_uses_resource" src="http://www.alexonlinux.com/wp-content/uploads/2011/09/user_uses_resource.png" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2011%2F09%2Fuser_uses_resource.png','user_uses_resource')" alt="" width="445" height="104" /></a></p>
<p>This is how <em>User class</em> uses <em>Resource class</em>.</p>
<h2>Contains and manages</h2>
<p><a href="http://www.alexonlinux.com/wp-content/uploads/2011/09/whole_part_managed.png" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2011%2F09%2Fwhole_part_managed.png','whole_part_managed')"><img class="size-full wp-image-1957 aligncenter" title="whole_part_managed" src="http://www.alexonlinux.com/wp-content/uploads/2011/09/whole_part_managed.png" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2011%2F09%2Fwhole_part_managed.png','whole_part_managed')" alt="" width="429" height="107" /></a></p>
<p>Here, <em>Whole</em> class contains and manages <em>Part </em>class. This type of relation can be extended to one of the following:</p>
<ul>
<li>One to One</li>
<li>One to Many</li>
<li>Many to One</li>
<li>Many to Many</li>
</ul>
<h2>References</h2>
<p><a href="http://www.alexonlinux.com/wp-content/uploads/2011/09/whole_part_unmanaged.png" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2011%2F09%2Fwhole_part_unmanaged.png','whole_part_unmanaged')"><img class="size-full wp-image-1959 aligncenter" title="whole_part_unmanaged" src="http://www.alexonlinux.com/wp-content/uploads/2011/09/whole_part_unmanaged.png" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2011%2F09%2Fwhole_part_unmanaged.png','whole_part_unmanaged')" alt="" width="382" height="103" /></a></p>
<p>Here, <em>Whole</em> class references to <em>Part</em> class, but does not manage it. Again, can be extended with:</p>
<ul>
<li>One to One</li>
<li>One to Many</li>
<li>Many to One</li>
<li>Many to Many</li>
</ul>
<p>&nbsp;</p>
<p>This is enough information for now. I&#8217;ll probably extend it over time. In any case, please post your corrections and suggestions.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/uml-cheatsheet/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Making writes durable &#8211; is your data on disk?</title>
		<link>http://www.alexonlinux.com/making-writes-durable-is-your-data-on-disk</link>
		<comments>http://www.alexonlinux.com/making-writes-durable-is-your-data-on-disk#comments</comments>
		<pubDate>Mon, 19 Sep 2011 16:26:03 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Programming Articles]]></category>
		<category><![CDATA[Short articles]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1942</guid>
		<description><![CDATA[Here is an interesting article written by Evan Jones. The article explains how you can be guaranteed when your data is on disk. In case you&#8217;re wondering, when write(), fwrite() or any other library call that writes data to disk reports success you are not guaranteed that the data is actually on the disk. In [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/what-is-direct-io-anyway' rel='bookmark' title='What is direct I/O anyway?'>What is direct I/O anyway?</a></li>
<li><a href='http://www.alexonlinux.com/multithreaded-simple-data-type-access-and-atomic-variables' rel='bookmark' title='Multithreaded simple data type access and atomic variables'>Multithreaded simple data type access and atomic variables</a></li>
<li><a href='http://www.alexonlinux.com/models-for-multithreaded-applications' rel='bookmark' title='Models for multithreaded applications'>Models for multithreaded applications</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.evanjones.ca/durable-writes.html" onclick="return TrackClick('http%3A%2F%2Fwww.evanjones.ca%2Fdurable-writes.html','Here+is')">Here is</a> an interesting article written by <a href="http://www.evanjones.ca/" onclick="return TrackClick('http%3A%2F%2Fwww.evanjones.ca%2F','Evan+Jones')">Evan Jones</a>. The article explains how you can be guaranteed when your data is on disk.</p>
<p>In case you&#8217;re wondering, when write(), fwrite() or any other library call that writes data to disk reports success you are not guaranteed that the data is actually on the disk. In fact, in Linux, write() reports success when data is in dirty cache. Then, special kernel thread kicks in and makes sure that the data is on disk.</p>
<p>Depending on circumstances, it may take some time until writer kernel thread will finish writing. Anyway, in his post Evan talks about how to make sure that the data is actually stable on disk.</p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/what-is-direct-io-anyway' rel='bookmark' title='What is direct I/O anyway?'>What is direct I/O anyway?</a></li>
<li><a href='http://www.alexonlinux.com/multithreaded-simple-data-type-access-and-atomic-variables' rel='bookmark' title='Multithreaded simple data type access and atomic variables'>Multithreaded simple data type access and atomic variables</a></li>
<li><a href='http://www.alexonlinux.com/models-for-multithreaded-applications' rel='bookmark' title='Models for multithreaded applications'>Models for multithreaded applications</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/making-writes-durable-is-your-data-on-disk/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Models for multithreaded applications</title>
		<link>http://www.alexonlinux.com/models-for-multithreaded-applications</link>
		<comments>http://www.alexonlinux.com/models-for-multithreaded-applications#comments</comments>
		<pubDate>Thu, 21 Apr 2011 22:00:18 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Programming Articles]]></category>
		<category><![CDATA[Short articles]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[scheduler]]></category>
		<category><![CDATA[synchronization]]></category>
		<category><![CDATA[thread]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1776</guid>
		<description><![CDATA[As you know, I changed a couple of workplaces during my career. Long story short, one interesting thing that I noticed in different companies is various models for multi-threaded programs (mostly for large embedded systems). Lets say we have a multi-threaded program.  The program should handle heterogeneous tasks. On a very basic level, our program [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/a-new-kind-of-virtualization' rel='bookmark' title='A new kind of virtualization'>A new kind of virtualization</a></li>
<li><a href='http://www.alexonlinux.com/cc-reference-counting-with-atomic-variables-and-gcc' rel='bookmark' title='C/C++ reference counting with atomic variables and gcc'>C/C++ reference counting with atomic variables and gcc</a></li>
<li><a href='http://www.alexonlinux.com/why-interrupt-affinity-with-multiple-cores-is-not-such-a-good-thing' rel='bookmark' title='Why interrupt affinity with multiple cores is not such a good thing'>Why interrupt affinity with multiple cores is not such a good thing</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>As you know, I changed a couple of workplaces during my career. Long story short, one interesting thing that I noticed in different companies is various models for multi-threaded programs (mostly for large embedded systems).</p>
<p><span id="more-1776"></span>Lets say we have a multi-threaded program.  The program should handle heterogeneous tasks. On a very basic level, our program probably receives some data, processes it and produces an output. Question of how to manage threads usually arises in performance critical applications. Otherwise, it is quiet simple &#8211; we squeeze into single thread as many tasks as possible.</p>
<p>Actual data processing may take several steps. We may want to split it to several tasks, each handled by thread of its own.</p>
<h2>Thread per task model</h2>
<p>When using this model, we allocate single thread per task. Since we want to pass work from one thread to another, we will need some synchronization mechanism.</p>
<p>I suppose we&#8217;ll need some queues to pass things between threads. Also, we may need muteces or semaphores to synchronize access to queues and other shared objects.</p>
<p>One obvious weakness of this approach is performance. When moving task objects from one thread to another we often move them from CPU to CPU. Modern CPUs heavily deploy caching mechanisms. So keeping objects local to one CPU brings significant performance boost. By moving task from one CPU to another we heart caching and cause performance degradation.</p>
<p>Another performance related problem is that while your task object moves from one thread to another it should undergo at least one context switch. Depending on overall number of tasks, time it takes to process single task can be greater. Another cause of context switches is mutual exclusion mechanism that have to protect the data structure used to communicate objects between threads.</p>
<p>One last significant performance issue that I would like to mention is in the core of this approach. Each thread is bound by processing power of a single core. But what if one of the tasks require more processing power. The computer may have enough processing power. This is especially true with recent multi-core trend. But when a single thread runs on one core at a time inevitably each thread processing the request, is a potential bottle-neck.</p>
<p>Advantage of this approach is in its simplicity. You don&#8217;t have to develop significant infrastructure to make it work. All you need is pthreads and a couple of classes that do the job. All tools that you will use are available out of the box. Because it is so common, it will be easier to find skilled and experienced engineers to implement and use with this model.</p>
<h2>Worker threads</h2>
<p>In this model, each task split into multiple jobs. Each job being handled by single thread. There is number of worker threads each taking care of at most single job at any particular moment. To improve performance, system tries to handle jobs that belong to same task on the same core. This means that there might be number of threads per single core.</p>
<p>Unlike thread per task model, this model is much more difficult to implement. It implies some constraints on the tasks:</p>
<ol>
<li>Engineer designing such system should be able to split tasks into multiple jobs. Alternatively, tasks can be very short.</li>
<li>Jobs should be more or less equal in size in terms of required processing resources.</li>
</ol>
<p>In addition, this approach requires smart task management. Such system should implement scheduler that spreads tasks between cores. A serios problem arises when number of running tasks becomes larger than number of cores in the system. When it happens, scheduler should start two or more tasks on single core. To do it wisely, it should be aware of how much processing power required by tasks. It should manage number of tasks running on particular core and assign new task to least busy core.</p>
<p>Needless to say that this approach is way more complex than naive thread per task model. It requires more skilled engineers. Moreover, these engineers should spend their time developing something that is not directly related to the matters of the project &#8211; that is various infrastructures for the project.</p>
<p>On the other hand, this approach allows engineers to squeeze every bit of performance out of the machine. This approach will take the hardware to its limit.</p>
<h2>Other approaches</h2>
<p>There are many other approaches of course. Most of them however, are an attempt to merge between two models I described. For instance, one company started with thread per task model for their embedded system and quickly ran into performance problems. So they tried to solve problems by splitting busiest tasks into multiple threads, basically changing threading model for one particular thread into worker threads model.</p>
<p>Recently I ran into another model that is somewhat unique. This model implements so called user-mode threads. Entire program runs in a single thread. Like worker threads model, in this model tasks split into smaller jobs. However, instead of letting the operating system to schedule between job execution, this model implements a user-mode scheduler.</p>
<p>The actual scheduling is made using setjmp() and longjmp() calls. One obvious constrain that this model presents is that if thread goes to sleep in operating system terms it will send entire system to sleep. As a result, the system should have very tight control over what threads does and in particular how it sleeps. I.e. threads are not allowed to do regular I/O. Instead they should do I/O in a centralized way.</p>
<p>For example, thread that wishes to read from a file-descriptor should register this file-descriptor with scheduler. Scheduler will select() or poll() on all registered file-descriptors. Depending on what file-descriptor requires attention, scheduler will schedule thread that takes care of that file-descriptor.</p>
<p>In this model you can run only a single instance of scheduler on single processor. So this model is not entierly optimized for MP machines. If you still want to run multiple schedulers on single computer then you can either run them in separate processes or multiple threads of the same process. In both cases communication between threads that belong to different schedulers is cumbersome. For instance if run multiple schedulers in multiple threads, you cannot use mutexes to synchronize between threads that belong to various schedulers because locking such mutex will send entire system to sleep. Instead you should use some sort of I/O based IPC.</p>
<p>Despite number of disadvantages that this approach has, there are couple of good things into it. Synchronizing between threads that belong to same instance of scheduler is much easier because there is, at most, one thread that runs at any particular moment. So, if, for instance, you have some simple data structure that being used by multiple threads there is no need to protect it from simultaneous access.</p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/a-new-kind-of-virtualization' rel='bookmark' title='A new kind of virtualization'>A new kind of virtualization</a></li>
<li><a href='http://www.alexonlinux.com/cc-reference-counting-with-atomic-variables-and-gcc' rel='bookmark' title='C/C++ reference counting with atomic variables and gcc'>C/C++ reference counting with atomic variables and gcc</a></li>
<li><a href='http://www.alexonlinux.com/why-interrupt-affinity-with-multiple-cores-is-not-such-a-good-thing' rel='bookmark' title='Why interrupt affinity with multiple cores is not such a good thing'>Why interrupt affinity with multiple cores is not such a good thing</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/models-for-multithreaded-applications/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Python for bash replacement</title>
		<link>http://www.alexonlinux.com/python-for-bash-replacement</link>
		<comments>http://www.alexonlinux.com/python-for-bash-replacement#comments</comments>
		<pubDate>Sun, 26 Dec 2010 16:25:37 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Programming Articles]]></category>
		<category><![CDATA[Short articles]]></category>
		<category><![CDATA[System Administrator Articles]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[ipython]]></category>
		<category><![CDATA[piping]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[redirections]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1847</guid>
		<description><![CDATA[When I started learning Python, I was looking for a programming language that would replace BASH, AWK and SED. I am a C/C++ programmer and as such I better invest my time into studying C and C++. Instead, every time I needed some complex script I opened up a book on BASH and refreshed my [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/6-things-that-i-miss-in-bash' rel='bookmark' title='6 things that I miss in bash'>6 things that I miss in bash</a></li>
<li><a href='http://www.alexonlinux.com/sed-the-missing-manual' rel='bookmark' title='sed &#8211; the missing manual'>sed &#8211; the missing manual</a></li>
<li><a href='http://www.alexonlinux.com/my-next-programming-language' rel='bookmark' title='My next programming language'>My next programming language</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>When I started learning Python, I was looking for a programming language that would replace BASH, AWK and SED. I am a C/C++ programmer and as such I better invest my time into studying C and C++. Instead, every time I needed some complex script I opened up a book on BASH and refreshed my knowledge. And since bumping into boundaries of what BASH can do is relatively easy, I always opened awk/sed book few minutes later.</p>
<p>Actually, this is quiet common. Once in a while I see my colleagues, just like myself, open up a book on BASH. The problem is that because we don&#8217;t actively program BASH, the knowledge and experience that we gain from this experience wear out over time. So next time we approach, so we have to repeatedly study BASH stuff over and over again. And again, this is not only BASH I am talking about, but also AWK and SED.</p>
<p>It is utterly broken state of affairs and I wish there was a solution. Unfortunately there is no solution yet. The good thing is that with some effort the solution may arise. I am talking about Python programming language.</p>
<p><span id="more-1847"></span></p>
<p>Needless to say that Python can do everything that BASH can do. However, it was never designed as shell environment and as such it is hardly convenient.</p>
<p>For instance, running external commands is easy. You should use subprocess module to run the command and there you go, you have both return value and the output. But this is miles away from convenience of simply typing the command and hitting enter.</p>
<p>Another issue is input/output redirections and piping. Regular shell does this with ease. Python obviously does this as well, but not without a hassle of importing the right module and creating the right object, etc.</p>
<p>On the other hand things are not that bad. For instance implementing command line should be somewhat easy in Python because it has native support for completion (which it uses in its own command line interface).</p>
<p>There is a project that makes few steps in the right direction. I am talking about IPython of course. Unfortunately, I doubt that IPython will ever be able to replace BASH. It was never their goal. Even though IPython developers implemented some features that make IPython command line a little down to earth, I am in doubt they will continue moving in this direction. Also, I must say that IPython evolves quiet slowly.</p>
<p>What do you think? Will Python ever be able to replace BASH?</p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/6-things-that-i-miss-in-bash' rel='bookmark' title='6 things that I miss in bash'>6 things that I miss in bash</a></li>
<li><a href='http://www.alexonlinux.com/sed-the-missing-manual' rel='bookmark' title='sed &#8211; the missing manual'>sed &#8211; the missing manual</a></li>
<li><a href='http://www.alexonlinux.com/my-next-programming-language' rel='bookmark' title='My next programming language'>My next programming language</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/python-for-bash-replacement/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>pthread_exit() in C++</title>
		<link>http://www.alexonlinux.com/pthread_exit-in-c</link>
		<comments>http://www.alexonlinux.com/pthread_exit-in-c#comments</comments>
		<pubDate>Sat, 09 Oct 2010 09:28:03 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Programming Articles]]></category>
		<category><![CDATA[Short articles]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[pthread]]></category>
		<category><![CDATA[stack]]></category>
		<category><![CDATA[unwinding]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1841</guid>
		<description><![CDATA[Today I ran into an interesting problem that I would like to share. I am working on multi-threaded code in C++. Here&#8217;s what happened. I started a thread that looks like this: try { do_something() } catch (...) { std::cout &#60;&#60; "Got unknown exception" &#60;&#60; std::endl; } The do_something() routine eventually called pthread_exit(). Once I [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/how-to-handle-sigsegv-but-also-generate-core-dump' rel='bookmark' title='How to handle SIGSEGV, but also generate a core dump'>How to handle SIGSEGV, but also generate a core dump</a></li>
<li><a href='http://www.alexonlinux.com/cc-reference-counting-with-atomic-variables-and-gcc' rel='bookmark' title='C/C++ reference counting with atomic variables and gcc'>C/C++ reference counting with atomic variables and gcc</a></li>
<li><a href='http://www.alexonlinux.com/signal-handling-in-linux' rel='bookmark' title='Signal handling in Linux'>Signal handling in Linux</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Today I ran into an interesting problem that I would like to share. I am working on multi-threaded code in C++. Here&#8217;s what happened.</p>
<p>I started a thread that looks like this:</p>
<pre class="brush:cpp;">try {
    do_something()
} catch (...) {
    std::cout &lt;&lt; "Got unknown exception" &lt;&lt; std::endl;
}</pre>
<p>The do_something() routine eventually called pthread_exit().</p>
<p>Once I ran this piece of code, I instantly got an unknown exception notification. Long story short, here&#8217;s what I found out.</p>
<p>When calling pthread_exit() in C++, it has to destruct all objects that has been created on stack. This process called stack unwinding and this is exactly what happens when you throw an exception. pthread_exit() utilizes this feature of C++ to cleanup before shutting down the thread for good.</p>
<p>To do that pthread_exit() throws some obscure exception and catches it right before ditching the thread. This way it cleans up all objects nicely. On the other hand, catching &#8230; becomes impossible.</p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/how-to-handle-sigsegv-but-also-generate-core-dump' rel='bookmark' title='How to handle SIGSEGV, but also generate a core dump'>How to handle SIGSEGV, but also generate a core dump</a></li>
<li><a href='http://www.alexonlinux.com/cc-reference-counting-with-atomic-variables-and-gcc' rel='bookmark' title='C/C++ reference counting with atomic variables and gcc'>C/C++ reference counting with atomic variables and gcc</a></li>
<li><a href='http://www.alexonlinux.com/signal-handling-in-linux' rel='bookmark' title='Signal handling in Linux'>Signal handling in Linux</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/pthread_exit-in-c/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My next programming language</title>
		<link>http://www.alexonlinux.com/my-next-programming-language</link>
		<comments>http://www.alexonlinux.com/my-next-programming-language#comments</comments>
		<pubDate>Sun, 22 Aug 2010 21:04:43 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Programming Articles]]></category>
		<category><![CDATA[bazaar]]></category>
		<category><![CDATA[CVS]]></category>
		<category><![CDATA[evolution]]></category>
		<category><![CDATA[future]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming language]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[version control system]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1819</guid>
		<description><![CDATA[This week-end I&#8217;ve been playing with various version control systems. Until now, I&#8217;ve been doing all my home codings with subversion. I&#8217;ve written


Related posts:<ol><li><a href='http://www.alexonlinux.com/distributed-vs-centralized-version-control-systems' rel='bookmark' title='Distributed vs. centralized version control systems'>Distributed vs. centralized version control systems</a></li>
<li><a href='http://www.alexonlinux.com/bazaar-for-subversion-users-part-1-the-basics' rel='bookmark' title='Bazaar for subversion users, part 1 &#8211; the basics'>Bazaar for subversion users, part 1 &#8211; the basics</a></li>
<li><a href='http://www.alexonlinux.com/todo-list' rel='bookmark' title='Todo list'>Todo list</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This week-end I&#8217;ve been playing with various version control systems. Until now, I&#8217;ve been doing all my home codings with subversion. I&#8217;ve written <a title="Link to article about bazaar" href="bazaar-for-subversion-users-part-1-the-basics" onclick="return TrackClick('bazaar-for-subversion-users-part-1-the-basics" onclick="return TrackClick('bazaar-for-subversion-users-part-1-the-basics','Link+to+article+about+bazaar')",'Link+to+article+about+bazaar')">about bazaar in the past</a>, but it seems to me that <a href="http://stackoverflow.com/questions/995636/popularity-of-git-mercurial-bazaar-vs-which-to-recommend">bazaar isn&#8217;t going anywhere</a> and it busts any piece of motivation that I have to continue writing about it.</p>
<p>Version control that I did try is git. This is a very popular version control system and for a good reason. Comparing git and subversion brought me to a conclusion that git is really a very consequence of how things work in the world. Thing about git is that it is a distributed version control while subversion is not. You can make a distributed version of subversion, but it won&#8217;t be subversion anymore.</p>
<p>Distributivity is one thing, but there are more. Take the standard trunk/branches/tags layout that you have to create in subversion &#8211; version control could do it for you, as git/bazaar/mercurial do. At first, after working with CVS for some time, having an option to have non-standard layout seemed cool for some time. But then it appeared completely useless.</p>
<p>This brings a notion of evolution into version control systems and I bet there&#8217;s similar process with programming languages. I think we can already starting drawing a programming language that will replace Python.</p>
<p>Yep, Python isn&#8217;t perfect. I thought I&#8217;d compile a list of things that shall be different in ought to be programming language that comes after Python.</p>
<p><span id="more-1819"></span></p>
<ol>
<li>Passing <em>self</em> to methods is counter-productive. Using <em>self</em> to access members is super counter productive. Yet this is how Python works. Without this, it won&#8217;t be Python anymore.</li>
<li>Same thing with <em>global</em>. Every program has this one global variable that every other class and function use. So, every entity that uses that variable has to declare it with <em>global</em> keyword. Utterly counter-productive.</li>
<li>Starting every private method and field with __ (double under-score) is ugly. The way it changes method name prepending it with a class name is even uglier. It is a really hackish way to handle this problem. I understand that this is the Python way of doing things, but it feels wrong.</li>
<li>Another hackish thing are decorators. Make an option to have static methods, class methods and properties and decorators are gone. No one would need them anymore, and it will be one bit easier to master Python.</li>
<li>You name it.</li>
</ol>
<p><em>Disclaimer (can&#8217;t get along without one this time <img src='http://www.alexonlinux.com/wp-content/plugins/smilies-themer/modern/smile.gif' alt=':-)' class='wp-smiley' /> ): This post may seem like one criticizing Python and it does in some ways, but I doubt these can be fixed in something called Python (unless Guido van Rossum brews it and calls it P</em><em>ython 4). In the meantime I love Python and use it on a daily basis. </em></p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/distributed-vs-centralized-version-control-systems' rel='bookmark' title='Distributed vs. centralized version control systems'>Distributed vs. centralized version control systems</a></li>
<li><a href='http://www.alexonlinux.com/bazaar-for-subversion-users-part-1-the-basics' rel='bookmark' title='Bazaar for subversion users, part 1 &#8211; the basics'>Bazaar for subversion users, part 1 &#8211; the basics</a></li>
<li><a href='http://www.alexonlinux.com/todo-list' rel='bookmark' title='Todo list'>Todo list</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/my-next-programming-language/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Call a constructor or allocate an object in-place</title>
		<link>http://www.alexonlinux.com/call-a-constructor-or-allocate-an-object-in-place-2</link>
		<comments>http://www.alexonlinux.com/call-a-constructor-or-allocate-an-object-in-place-2#comments</comments>
		<pubDate>Sun, 04 Jul 2010 20:40:10 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[Programming Articles]]></category>
		<category><![CDATA[Short articles]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[memory management]]></category>
		<category><![CDATA[new]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1803</guid>
		<description><![CDATA[Since I joined Dell, my main field of research and work has somewhat changed. Now I am mostly working with C++ and file-systems. This world is not entirely new to me, but apparently I have a lot of stuff to learn. Today I&#8217;d like to talk about one nice trick that I learned few days [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/direct-io-in-python' rel='bookmark' title='Direct IO in Python'>Direct IO in Python</a></li>
<li><a href='http://www.alexonlinux.com/one-sane-voice-in-the-crowd' rel='bookmark' title='One sane voice in the crowd'>One sane voice in the crowd</a></li>
<li><a href='http://www.alexonlinux.com/recursively-deleting-symbolic-link-and-what-it-points-to' rel='bookmark' title='Recursively deleting symbolic link and what it points to'>Recursively deleting symbolic link and what it points to</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Since I joined Dell, my main field of research and work has somewhat changed. Now I am mostly working with C++ and file-systems. This world is not entirely new to me, but apparently I have a lot of stuff to learn.</p>
<p>Today I&#8217;d like to talk about one nice trick that I learned few days ago.</p>
<p>When working with large software systems, memory management becomes an imperative. In C, you can easily allocate a large chunk of memory and allocate structure right on that buffer. This is by far more difficult in C++, because compiler has to call consturctor.</p>
<p>Apparently, you can, in a way, directly call object&#8217;s constructor . I.e. you can allocate an object, on specified memory region, without actually allocating this region.</p>
<p>This is how you do it.</p>
<pre class="brush:cpp">char* s = new char[1024];

SomeClass* p = new (s) SomeClass;
</pre>
<p>First new operator just allocates 1024 bytes. This is good old allocation as we know it. Note the special syntax of the second new operator. It allocates the new object on memory specified in brackets. Basically, this calls SomeClass&#8217;s constructor using s as storage.</p>
<p><em>One thing that I don&#8217;t know how to do is how to call destructor on the object &#8211; i.e. how to delete an object in place.</em></p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/direct-io-in-python' rel='bookmark' title='Direct IO in Python'>Direct IO in Python</a></li>
<li><a href='http://www.alexonlinux.com/one-sane-voice-in-the-crowd' rel='bookmark' title='One sane voice in the crowd'>One sane voice in the crowd</a></li>
<li><a href='http://www.alexonlinux.com/recursively-deleting-symbolic-link-and-what-it-points-to' rel='bookmark' title='Recursively deleting symbolic link and what it points to'>Recursively deleting symbolic link and what it points to</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/call-a-constructor-or-allocate-an-object-in-place-2/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>This is me, couple of weeks ago.</title>
		<link>http://www.alexonlinux.com/this-is-me-couple-of-weeks-ago</link>
		<comments>http://www.alexonlinux.com/this-is-me-couple-of-weeks-ago#comments</comments>
		<pubDate>Tue, 11 May 2010 16:25:29 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1792</guid>
		<description><![CDATA[I think this is going to become my new icon. What do you think? No related posts.


No related posts.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.alexonlinux.com/wp-content/uploads/2010/05/me.jpg" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2010%2F05%2Fme.jpg','me')"><img class="aligncenter size-full wp-image-1791" title="me" src="http://www.alexonlinux.com/wp-content/uploads/2010/05/me.jpg" onclick="return TrackClick('http%3A%2F%2Fwww.alexonlinux.com%2Fwp-content%2Fuploads%2F2010%2F05%2Fme.jpg','me')" alt="" width="598" height="398" /></a></p>
<p>I think this is going to become my new icon. What do you think?</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/this-is-me-couple-of-weeks-ago/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How less processes its input</title>
		<link>http://www.alexonlinux.com/how-less-processes-its-input</link>
		<comments>http://www.alexonlinux.com/how-less-processes-its-input#comments</comments>
		<pubDate>Wed, 28 Apr 2010 13:37:37 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Programming Articles]]></category>
		<category><![CDATA[Short articles]]></category>
		<category><![CDATA[curses]]></category>
		<category><![CDATA[error stream]]></category>
		<category><![CDATA[file descriptor]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[input stream]]></category>
		<category><![CDATA[less]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[more]]></category>
		<category><![CDATA[output stream]]></category>
		<category><![CDATA[tty]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1783</guid>
		<description><![CDATA[Here&#8217;s an interesting bit I ran into few days ago. I got curious how is that less (or more) can read file contents from standard input and yet it is able to process input that comes from user. Both of them come from standard input, yet these are quiet heterogeneous streams of information. So, how [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/creating-new-application-on-top-of-ssh' rel='bookmark' title='Creating new application on top of SSH'>Creating new application on top of SSH</a></li>
<li><a href='http://www.alexonlinux.com/sed-the-missing-manual' rel='bookmark' title='sed &#8211; the missing manual'>sed &#8211; the missing manual</a></li>
<li><a href='http://www.alexonlinux.com/direct-io-in-python' rel='bookmark' title='Direct IO in Python'>Direct IO in Python</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an interesting bit I ran into few days ago. I got curious how is that <em>less</em> (or <em>more</em>) can read file contents from standard input and yet it is able to process input that comes from user. Both of them come from standard input, yet these are quiet heterogeneous streams of information. So, how can it be?</p>
<p><span id="more-1783"></span>At first, I thought <em>less</em> reads entire input first. This would make standard input stream free to process key presses from the user. So I decided to check this out. I created a 1Gb long text file and ran <em>less</em> on it. I expected <em>less</em> to take some time to show file contents, but it showed first lines of the file instantly. Also, it didn&#8217;t consume 1Gb of RAM as I expected.</p>
<p>The conclusion is obvious. <em>less</em> does not read entire input buffer before letting user to interact with itself. Then how?</p>
<p>Here&#8217;s what <em>less</em> does. It separates input file stream from user input stream. Both inputs initially come via standard input stream, so <em>less</em> separates between them. First it duplicates the standard input stream. This allocates a new file descriptor. Then it closes old file descriptor, freeing file descriptor 0 for use. Then it opens /dev/tty. When opening a file, Linux uses next available file descriptor. File descriptor used as standard input is 0, so when <em>less</em> opens /dev/tty again, file descriptor of the newly opened file has value 0.</p>
<p>Eventually, it ends up with the new input coming via standard input stream file descriptor (0), and old input still available via file descriptor that it duplicated in the beginning. It reads the input file from the duplicated file descriptor, and uses curses on standard input stream.</p>
<p>You may be wondering what is /dev/tty and what it has to do with standard input streams. This is really fascinating stuff.</p>
<p>As you know, in Linux, everything is a file. So is terminal. Linux uses device files to represent various system devices. /dev/tty is a file that represents terminal of the current process. When process reads from /dev/tty it becomes its input. When program writes to /dev/tty it becomes its standard output or standard error stream.</p>
<p>So, when <em>less </em>reopens /dev/tty, it actually recreates standard input. Older descriptor, one that has been duplicated, can no longer accept new input, but <em>less</em> still can use it to read what it has been written into it already.</p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/creating-new-application-on-top-of-ssh' rel='bookmark' title='Creating new application on top of SSH'>Creating new application on top of SSH</a></li>
<li><a href='http://www.alexonlinux.com/sed-the-missing-manual' rel='bookmark' title='sed &#8211; the missing manual'>sed &#8211; the missing manual</a></li>
<li><a href='http://www.alexonlinux.com/direct-io-in-python' rel='bookmark' title='Direct IO in Python'>Direct IO in Python</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/how-less-processes-its-input/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I got a new job, take 3</title>
		<link>http://www.alexonlinux.com/i-got-a-new-job-take-3</link>
		<comments>http://www.alexonlinux.com/i-got-a-new-job-take-3#comments</comments>
		<pubDate>Tue, 02 Mar 2010 11:51:36 +0000</pubDate>
		<dc:creator>Alexander Sandler</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.alexonlinux.com/?p=1740</guid>
		<description><![CDATA[I got a new job, again. Dell decided to obtain what have left of Exanet LTD, a company I worked for in the past. They kindly decided to offer a job to majority of ex-Exanet engineers, me included. So, I decided to leave Fabrix and as of last week I am software engineer and senior [...]


Related posts:<ol><li><a href='http://www.alexonlinux.com/resume' rel='bookmark' title='Resume'>Resume</a></li>
<li><a href='http://www.alexonlinux.com/i-am-looking-for-a-new-job' rel='bookmark' title='I am looking for a new job'>I am looking for a new job</a></li>
<li><a href='http://www.alexonlinux.com/what-it-takes-to-be-a-qa-engineer' rel='bookmark' title='What it takes to be a QA engineer'>What it takes to be a QA engineer</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I got a new job, again. Dell decided to obtain what have left of Exanet LTD, <a href="i-got-a-new-job">a company I worked for in the past</a>. They kindly decided to offer a job to majority of ex-Exanet engineers, me included.</p>
<p>So, I decided to leave Fabrix and as of last week I am software engineer and senior consultant at Dell IDC (Israel Developer Center).</p>


<p>Related posts:<ol><li><a href='http://www.alexonlinux.com/resume' rel='bookmark' title='Resume'>Resume</a></li>
<li><a href='http://www.alexonlinux.com/i-am-looking-for-a-new-job' rel='bookmark' title='I am looking for a new job'>I am looking for a new job</a></li>
<li><a href='http://www.alexonlinux.com/what-it-takes-to-be-a-qa-engineer' rel='bookmark' title='What it takes to be a QA engineer'>What it takes to be a QA engineer</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alexonlinux.com/i-got-a-new-job-take-3/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

