<?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>keeping simple &#187; threads</title>
	<atom:link href="http://www.yodaiken.com/tag/threads/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.yodaiken.com</link>
	<description>Systems software technology and business</description>
	<lastBuildDate>Sun, 01 Jan 2012 18:30:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Program structure and threads</title>
		<link>http://www.yodaiken.com/2009/03/program-structure-and-threads/</link>
		<comments>http://www.yodaiken.com/2009/03/program-structure-and-threads/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 04:46:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[architecture]]></category>
		<category><![CDATA[operating systems]]></category>
		<category><![CDATA[software engineering]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://www.yodaiken.com/?p=243</guid>
		<description><![CDATA[Threads were initially used for telephony systems where each request to connect could be given to a new thread to manage. The simplification was, in theory, dramatic. The programmer could just write the code for handling a single line, and &#8230; <a href="http://www.yodaiken.com/2009/03/program-structure-and-threads/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Threads were initially used for telephony systems where each request to connect could be given to a new thread to manage. The simplification was, in theory, dramatic. The programmer could just write the code for handling a single line, and the OS and network code would multiplex operation over 100,000 calls. The programmer does not have to worry about what operations blockÂ  and delays. Imagine writing this same code using some sort of request queue. The only way to do it would be to make extensive use of asynchronous I/O, something that was uncommon when threads became popular.Â  In fact, any multithreading design seems convertible into a single threaded design via use of asynchronous events and asynchronous I/O. But these methods are not noticeably easier than threads.</p>
<p>rcvm(fd, &amp;buf, n, func); // call &#8220;func&#8221; when the data arrives &#8211; pass it the return val and arguments to read as well</p>
<p>then</p>
<p>while(1){</p>
<p>rcvm(fd,&amp;ptr++,n,got);</p>
<p>if(noresources)wait();</p>
<p>}</p>
<p>got(fd,&amp;p,n,code){</p>
<p>look at message</p>
<p>queue_response</p>
<p>return;</p>
<p>}</p>
<p>Worse or better?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yodaiken.com/2009/03/program-structure-and-threads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Are threads evil? (updated)</title>
		<link>http://www.yodaiken.com/2009/02/are-threads-evil/</link>
		<comments>http://www.yodaiken.com/2009/02/are-threads-evil/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 19:18:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[embedded systems]]></category>
		<category><![CDATA[operating systems]]></category>
		<category><![CDATA[real-time]]></category>
		<category><![CDATA[rtlinux]]></category>
		<category><![CDATA[software engineering]]></category>
		<category><![CDATA[formal methods]]></category>
		<category><![CDATA[parallelism]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://www.yodaiken.com/?p=220</guid>
		<description><![CDATA[This paper by Prof. Edward Lee explains something of why &#8220;threads&#8221; are such a painful abstraction.  As Prof. Lee notes, threads intrinsically create non-determinism and resource conflicts which we then attempt to &#8220;prune&#8221; via synchronization and complex tools. In an &#8230; <a href="http://www.yodaiken.com/2009/02/are-threads-evil/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This <a title="evil threads" href="http://www.yodaiken.com/references/threadsareevil.pdf" target="_blank">paper </a>by Prof. Edward Lee explains something of why &#8220;threads&#8221; are such a painful abstraction.  As Prof. Lee notes, threads intrinsically create non-determinism and resource conflicts which we then attempt to &#8220;prune&#8221; via synchronization and complex tools. In an <a href="http://www.yodaiken.com/papers/sync.pdf">earlier note</a>, I argued that we should design real-time multi-threaded applications to minimize the need for synchronization, but Prof. Lee goes further to point out that the thread model itself encourages a disorganized program structure.  Along those lines, one of the basic difficulties in real-time application design is non-deterministic resource allocation. How can we ever be sure that, for example, a multi-threaded app where threads can allocate memory has sufficient memory for critical threads to proceed?</p>
<p>I&#8217;m not a fan of the &#8220;algebraic&#8221; <a title="Tagged Signal Model" href="http://www.eecs.berkeley.edu/Pubs/TechRpts/2005/EECS-2005-31.pdf" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.eecs.berkeley.edu/Pubs/TechRpts/2005/EECS-2005-31.pdf?referer=');">tagged model</a> that Lee suggests as an alternative &#8211; too much of the flavor of &#8220;formal methods&#8221; via the denotational semantics base.  In fact, Liu&#8217;s thesis, referenced here, struggles mightly with the unsatisfactory nature of the mathematical framework to get somewhere. Do we really have to create lemmas about posets to describe 2 simple processes? It seems to me that the confusion of the underlying mathematical basis has to be resolved before we can figure this out. Or maybe not.</p>
<p>Consider a really dumb system that keeps a &#8220;gain&#8221; variable, outputs a single analog voltage, and inputs both an input signal and &#8220;messages&#8221; that tell it what to do. The input events can be thought of as samples of the analog signals on the &#8220;pins&#8221;.</p>
<p>Inputs are maps: Pins -&gt; Signals  where each input represents one unit of time and the set Pins contains &#8220;Vin&#8221; and some unknown number of pins (which may not be actual physical pins) comprising the message port.</p>
<p>Given a sequence of inputs, w, we suppose we have a function LastGain(w) that extracts the value of gain we were told to set in the most recent message and SinceLastCommand(w) that counts samples (time units) since the last command message.  Let&#8217;s be more specific on the &#8220;Vin&#8221;</p>
<p>LastVin(wa) = a(Vin).</p>
<p>StableVin(wa) = (1+ StableVin(w))*[a(Vin) ==Â  LastVin(w)]Â  where [exp] is 1 if exp is true and 0 otherwise</p>
<p>StableVin(emptysequence)=0</p>
<p>Then we can require that Dev(w)= g*v if</p>
<p>StableVin(w)&gt;= t1 and v=LastVin(w)</p>
<p>and g=LastCommand(w) and SinceLastCommand(w) &gt;= t2</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yodaiken.com/2009/02/are-threads-evil/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

