/usr/share/mozart/doc/apptut/node9.html is in mozart-doc 1.4.0-8ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>7 Concurrency For Free</TITLE><LINK href="ozdoc.css" rel="stylesheet" type="text/css"></HEAD><BODY><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node8.html">- Up -</A></TD><TD><A href="node10.html#chapter.concurrency.patterns">Next >></A></TD></TR></TABLE><DIV id="chapter.concurrency.cheap"><H1><A name="chapter.concurrency.cheap">7 Concurrency For Free</A></H1><P>This part of the tutorial addresses the following theme: what happens to programming when support for concurrency is extremely cheap, economical, and efficient. Suddenly, an entirely different style of programming and design is made possible. We are going to explore and exploit this new freedom.</P><P>Oz has very efficient, very economical, very lightweight threads, with fair preemptive scheduling. We don't mean that Oz threads are just somewhat better than brand X; we mean that brand X can't even see our dust with a telescope, er... well, just about anyway! In order to assuage the skeptics, we first exhibit a program that demonstrates massive concurrency and exercises the worst case. Doubters are encouraged to throw that program at their favorite programming language... and watch it die, eventually. Meanwhile, you could mount a clay tablet device, and engage in the more rewarding exercise of installing Windows from sumerian backup.</P><P>The program is invoked with: </P><BLOCKQUOTE class="code"><CODE>death --threads </CODE><I>N</I><CODE> --times </CODE><I>M</I></BLOCKQUOTE><P> and creates <I>N</I> threads. Each thread does nothing but <EM>yield</EM> immediately. Normally we would let the preemptive scheduler take care of interrupting a thread to switch to a new one, but here, in order to exercise the worst case, as soon as a thread is allowed to run, it explicitly <EM>yields</EM>. Thus the program does little else but switch between threads. Each thread yields <I>M</I> times and then terminates. When all threads have terminated, the program also terminates.</P><P>I just tried the following: </P><BLOCKQUOTE class="code"><CODE>death --threads 10000 --times 10</CODE></BLOCKQUOTE><P> In other words, 10000 threads are created and must each yield 10 times. This results in 100000 thread switches. It takes 3s on this little steam-driven laptop. I have run the same program on a real computer at the lab but using: </P><BLOCKQUOTE class="code"><CODE>death --threads 100000 --times 10</CODE></BLOCKQUOTE><P> It takes 7.5s. There are 100000 threads at all time runnable, and they must perform 1000000 thread switches. Try creating 100000 threads in Java... really, go ahead, I insist! I promise not to laugh!</P><P>Just so you don't have to take my word for it, I coded the same program in Java and tried: </P><BLOCKQUOTE class="code"><CODE>java Death 1000 10</CODE></BLOCKQUOTE><P> This takes 2:40mn!</P><P>What was the point of this exercise? It was not prove that Oz is better than Java; in this respect the test above was deliberately unfair: Java was never intended to support designs with massive concurrency... and <EM>that</EM> is the point. Oz was from the start designed as a platform for concurrent computation. That concurrency is so cheap and efficient makes entirely new designs possible that would not be realistic or even conceivable in other languages. Whenever you need to perform an operation asynchronously you simply spawn a new thread. You can design your application as a collection of concurrent objects or agents, etc...</P><DIV class="unnumbered" id="death.in.oz"><H2><A name="death.in.oz">Death by Concurrency in Oz</A></H2><P>Here is the code of the Oz application used in the benchmark above: </P><BLOCKQUOTE><PRE><SPAN class="keyword">functor</SPAN> <BR><SPAN class="keyword">import</SPAN> Application<BR><SPAN class="keyword">define</SPAN> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Yield</SPAN>} {Thread<SPAN class="keyword">.</SPAN>preempt {Thread<SPAN class="keyword">.</SPAN>this}} <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Run</SPAN> N}<BR> {Yield}<BR> <SPAN class="keyword">if</SPAN> N<SPAN class="keyword">></SPAN>1 <SPAN class="keyword">then</SPAN> {Run N<SPAN class="keyword">-</SPAN>1} <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> Args = {Application<SPAN class="keyword">.</SPAN>getCmdArgs<BR> record(threads(single type:int optional:<SPAN class="keyword">false</SPAN>)<BR> times( single type:int optional:<SPAN class="keyword">false</SPAN>))}<BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Main</SPAN> N AllDone}<BR> <SPAN class="keyword">if</SPAN> N<SPAN class="keyword">==</SPAN>0 <SPAN class="keyword">then</SPAN> AllDone=<SPAN class="keyword">unit</SPAN> <SPAN class="keyword">else</SPAN> RestDone <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">thread</SPAN> {Run Args<SPAN class="keyword">.</SPAN>times} AllDone=RestDone <SPAN class="keyword">end</SPAN> <BR> {Main N<SPAN class="keyword">-</SPAN>1 RestDone}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> {Wait {Main Args<SPAN class="keyword">.</SPAN>threads}}<BR> {Application<SPAN class="keyword">.</SPAN>exit 0}<BR><SPAN class="keyword">end</SPAN> <BR></PRE></BLOCKQUOTE><P></P></DIV><DIV class="unnumbered"><H2><A name="label21">Death by Concurrency in Java</A></H2><P>Here is a very similar program, in Java: </P><BLOCKQUOTE><PRE><SPAN class="keyword">import</SPAN> <SPAN class="reference">java</SPAN>.<SPAN class="reference">lang</SPAN>.*;<BR><SPAN class="keyword">class</SPAN> <SPAN class="type">MiniThread</SPAN> <SPAN class="keyword">extends</SPAN> <SPAN class="type">Thread</SPAN> {<BR> <SPAN class="type">int</SPAN> <SPAN class="variablename">n</SPAN>;<BR> MiniThread(<SPAN class="type">int</SPAN> <SPAN class="variablename">m</SPAN>) { n=m; }<BR> <SPAN class="keyword">public</SPAN> <SPAN class="type">void</SPAN> <SPAN class="functionname">run</SPAN>() {<BR> <SPAN class="keyword">do</SPAN> { yield(); n--; } <SPAN class="keyword">while</SPAN> (n>0);<BR> }<BR>}<BR><SPAN class="keyword">public</SPAN> <SPAN class="keyword">class</SPAN> <SPAN class="type">Death</SPAN> {<BR> <SPAN class="keyword">public</SPAN> <SPAN class="keyword">static</SPAN> <SPAN class="type">void</SPAN> <SPAN class="functionname">main</SPAN>(<SPAN class="type">String</SPAN>[] <SPAN class="variablename">argv</SPAN>) {<BR> <SPAN class="type">int</SPAN> <SPAN class="variablename">threads</SPAN> = Integer.parseInt(argv[0]);<BR> <SPAN class="type">int</SPAN> <SPAN class="variablename">times</SPAN> = Integer.parseInt(argv[1]);<BR> <SPAN class="keyword">for</SPAN>(<SPAN class="type">int</SPAN> <SPAN class="variablename">i</SPAN>=threads;i>0;i--) {<BR> <SPAN class="type">MiniThread</SPAN> <SPAN class="variablename">t</SPAN> = <SPAN class="keyword">new</SPAN> <SPAN class="type">MiniThread</SPAN>(i);<BR> t.<SPAN class="type">start</SPAN>();<BR> }<BR> }<BR>}<BR></PRE></BLOCKQUOTE><P></P></DIV></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node8.html">- Up -</A></TD><TD><A href="node10.html#chapter.concurrency.patterns">Next >></A></TD></TR></TABLE><HR><ADDRESS><A href="http://www.ps.uni-sb.de/~duchier/">Denys Duchier</A>, <A href="http://www.ps.uni-sb.de/~kornstae/">Leif Kornstaedt</A> and <A href="http://www.ps.uni-sb.de/~schulte/">Christian Schulte</A><BR><SPAN class="version">Version 1.4.0 (20110908185330)</SPAN></ADDRESS></BODY></HTML>
|