<?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>satori code &#187; Language</title>
	<atom:link href="http://satoricode.com/category/language/feed/" rel="self" type="application/rss+xml" />
	<link>http://satoricode.com</link>
	<description>Michael Trelinski&#039;s Technology Blog</description>
	<lastBuildDate>Fri, 26 Feb 2010 19:13:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Quick threaded app with &#8220;Go&#8221;</title>
		<link>http://satoricode.com/2009/11/19/quick-threaded-app-with-go/</link>
		<comments>http://satoricode.com/2009/11/19/quick-threaded-app-with-go/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 23:21:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Language]]></category>
		<category><![CDATA[go threads goroutine go test]]></category>

		<guid isPermaLink="false">http://satoricode.com/?p=12</guid>
		<description><![CDATA[Wow, seriously, hats off to Google on this one&#8230;  This should make threaded apps programming easier in the future for me.  They have created a language called &#8220;Go&#8221;, which in my opinion, looks like if Python and C++ had a child out of wedlock.  I don&#8217;t think I&#8217;ll be able to stop gushing about Go [...]]]></description>
			<content:encoded><![CDATA[<p>Wow, seriously, hats off to Google on this one&#8230;  This should make threaded apps programming easier in the future for me.  They have created a language called &#8220;Go&#8221;, which in my opinion, looks like if Python and C++ had a child out of wedlock.  I don&#8217;t think I&#8217;ll be able to stop gushing about Go for a while.  I believe I have found my new prototyping language, however, I don&#8217;t see a reason why this couldn&#8217;t run production code&#8230;</p>
<p>Check out this snippet of <a title="Go" href="http://golang.org" target="_blank">Go</a> code:</p>
<p>file: threads.go</p>
<pre><span style="font-family: Georgia; line-height: 19px; white-space: normal;">p</span>ackage main</pre>
<p> </p>
<pre>import "fmt"</pre>
<pre>import "syscall"</pre>
<p> </p>
<pre>const THREADS = 2;</pre>
<p> </p>
<pre>func threadtest(a int) {</pre>
<pre style="padding-left: 30px;">fmt.Printf("Thread %d started.\n", a);</pre>
<pre style="padding-left: 30px;">syscall.Sleep(10);</pre>
<pre style="padding-left: 30px;">for true {</pre>
<pre style="padding-left: 60px;">for i := 0; i &lt; 10; i++ {</pre>
<pre style="padding-left: 90px;">fmt.Printf("Thread %d -&gt; %d \n", a, i);</pre>
<pre style="padding-left: 60px;">}</pre>
<pre style="padding-left: 30px;">}</pre>
<pre>}</pre>
<p> </p>
<p> </p>
<pre>func waitforever(debug int) {</pre>
<pre style="padding-left: 30px;">for true {</pre>
<pre style="padding-left: 60px;">if debug == 1 {</pre>
<pre style="padding-left: 90px;">fmt.Printf(".");</pre>
<pre style="padding-left: 60px;">} else {</pre>
<pre style="padding-left: 90px;">fmt.Printf("");</pre>
<pre style="padding-left: 60px;">}</pre>
<pre style="padding-left: 30px;">}</pre>
<pre>}</pre>
<p> </p>
<p> </p>
<pre>func main() {</pre>
<pre style="padding-left: 30px;">fmt.Printf("testing threads:\n");</pre>
<pre style="padding-left: 30px;">for i := 0; i &lt; THREADS; i++ {</pre>
<pre style="padding-left: 60px;">go threadtest(i);</pre>
<pre style="padding-left: 30px;">}</pre>
<pre style="padding-left: 30px;">waitforever(0);</pre>
<pre>}</pre>
<p>Output:</p>
<p> </p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">$ ./threads</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">testing threads:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 0 started.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 1 started.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 0 -&gt; 0 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 1 -&gt; 0 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 0 -&gt; 1 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 1 -&gt; 1 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 0 -&gt; 2 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 1 -&gt; 2 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 0 -&gt; 3 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 1 -&gt; 3 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 0 -&gt; 4 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 1 -&gt; 4 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 0 -&gt; 5 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 1 -&gt; 5 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 0 -&gt; 6 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 1 -&gt; 6 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 0 -&gt; 7 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 1 -&gt; 7 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 0 -&gt; 8 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 1 -&gt; 8 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 0 -&gt; 9 </div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 883px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Thread 1 -&gt; 9 </div>
<p>$ ./threads</p>
<p>testing threads:</p>
<p>Thread 0 started.</p>
<p>Thread 1 started.</p>
<p>Thread 0 -&gt; 0 </p>
<p>Thread 1 -&gt; 0 </p>
<p>Thread 0 -&gt; 1 </p>
<p>Thread 1 -&gt; 1 </p>
<p>Thread 0 -&gt; 2 </p>
<p>Thread 1 -&gt; 2 </p>
<p>Thread 0 -&gt; 3 </p>
<p>Thread 1 -&gt; 3 </p>
<p>Thread 0 -&gt; 4 </p>
<p>Thread 1 -&gt; 4 </p>
<p>Thread 0 -&gt; 5 </p>
<p>Thread 1 -&gt; 5 </p>
<p>Thread 0 -&gt; 6 </p>
<p>Thread 1 -&gt; 6 </p>
<p>Thread 0 -&gt; 7 </p>
<p>Thread 1 -&gt; 7 </p>
<p>Thread 0 -&gt; 8 </p>
<p>Thread 1 -&gt; 8 </p>
<p>Thread 0 -&gt; 9 </p>
<p>Thread 1 -&gt; 9 </p>
<div>True (easy) concurrency!  The magic happens on &#8220;go threadtest(&#8230;)&#8221;, this is called a &#8220;goroutine.&#8221;  I&#8217;ll try to write some more Go-code later&#8230; cheers!</div>
]]></content:encoded>
			<wfw:commentRss>http://satoricode.com/2009/11/19/quick-threaded-app-with-go/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
