<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
h1
        {margin-top:12.0pt;
        margin-right:0cm;
        margin-bottom:3.0pt;
        margin-left:21.6pt;
        text-indent:-21.6pt;
        page-break-before:always;
        page-break-after:avoid;
        mso-list:l0 level1 lfo4;
        font-size:16.0pt;
        font-family:Arial;}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:Arial;
        color:windowtext;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:595.3pt 841.9pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.Section1
        {page:Section1;}
 /* List Definitions */
 @list l0
        {mso-list-id:1450051809;
        mso-list-template-ids:-1203760054;}
@list l0:level1
        {mso-level-style-link:"Heading 1";
        mso-level-text:%1;
        mso-level-tab-stop:21.6pt;
        mso-level-number-position:left;
        margin-left:21.6pt;
        text-indent:-21.6pt;}
@list l0:level2
        {mso-level-text:"%1\.%2";
        mso-level-tab-stop:28.8pt;
        mso-level-number-position:left;
        margin-left:28.8pt;
        text-indent:-28.8pt;}
@list l0:level3
        {mso-level-text:"%1\.%2\.%3";
        mso-level-tab-stop:36.0pt;
        mso-level-number-position:left;
        margin-left:36.0pt;
        text-indent:-36.0pt;}
@list l0:level4
        {mso-level-text:"%1\.%2\.%3\.%4";
        mso-level-tab-stop:43.2pt;
        mso-level-number-position:left;
        margin-left:43.2pt;
        text-indent:-43.2pt;}
@list l0:level5
        {mso-level-text:"%1\.%2\.%3\.%4\.%5";
        mso-level-tab-stop:50.4pt;
        mso-level-number-position:left;
        margin-left:50.4pt;
        text-indent:-50.4pt;}
@list l0:level6
        {mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6";
        mso-level-tab-stop:57.6pt;
        mso-level-number-position:left;
        margin-left:57.6pt;
        text-indent:-57.6pt;}
@list l0:level7
        {mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7";
        mso-level-tab-stop:64.8pt;
        mso-level-number-position:left;
        margin-left:64.8pt;
        text-indent:-64.8pt;}
@list l0:level8
        {mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8";
        mso-level-tab-stop:72.0pt;
        mso-level-number-position:left;
        margin-left:72.0pt;
        text-indent:-72.0pt;}
@list l0:level9
        {mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.%9";
        mso-level-tab-stop:79.2pt;
        mso-level-number-position:left;
        margin-left:79.2pt;
        text-indent:-79.2pt;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
-->
</style>

</head>

<body lang=NO-BOK link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>Posting a
code-snip that show you how to multi-thread &#8221;hello World&#8221; in V8. It
isn&#8217;t that complex once you understand that V8 contain it&#8217;s own
preemtive scheduler and is part operating system in nature.<o:p></o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>The big upside is
the next step &#8211; because threads are a budget on any PC, and we need the
threads for the voice transport in FS &#8211; so I will use a pool with 10
processes x 10 threads and throw a RTOS scheduler in front of each thread &#8211;
meaning each thread will in reality proceess 100-1000 calls. This will solve
what have been my main heacache so far - the CCXML/VXML threading budget. It
should also work smoothly with FS as it don&#8217;t start competing with FS on
the thread budget.<o:p></o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>The only drawback
is that this will not run on a Sparc, but well . . . <o:p></o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font
color=green><span style='color:green'>// Lock V8 so we single thread access to
V8. You MUST<o:p></o:p></span></font></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font
color=green><span style='color:green'>// use the V8 Locker scope for this<o:p></o:p></span></font></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v8::Locker
locker;<o:p></o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font
color=green><span style='color:green'>// Start the preemtive scheduler with a
10ms timer. This only<o:p></o:p></span></font></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font
color=green><span style='color:green'>// needs calling once, but adding it here
don't hurt.<o:p></o:p></span></font></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; locker.StartPreemption(10);<o:p></o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font
color=green><span style='color:green'>// Set scope.<o:p></o:p></span></font></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HandleScope
handle_scope;<o:p></o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font
color=green><span style='color:green'>// Create this threads contect inside the
scope. <o:p></o:p></span></font></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Persistent&lt;Context&gt;
context = Context::New();<o:p></o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Context::Scope
context_scope(context);<o:p></o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font
color=green><span style='color:green'>// create a source-code variable to hold
javascript. <o:p></o:p></span></font></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Handle&lt;String&gt;
source = String::New(<font color="#a31515"><span style='color:#A31515'>&quot;for(j
= 0; j&lt;100;j++)\n&#8221;<o:p></o:p></span></font></span></font></p>

<p class=MsoNormal style='margin-left:247.8pt;text-indent:35.4pt;text-autospace:
none'><font size=2 color="#a31515" face="Courier New"><span lang=EN-GB
style='font-size:10.0pt;font-family:"Courier New";color:#A31515'>&#8221;i='Hello'
+ ', World!'&quot;</span></font><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>);<o:p></o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font
color=green><span style='color:green'>// So far we have just created the basics
we need. <o:p></o:p></span></font></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font
color=green><span style='color:green'>// Now we will start a rt-loop where we
compile &amp; run.<o:p></o:p></span></font></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Handle&lt;Script&gt;
script;<o:p></o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Handle&lt;Value&gt;
result;<o:p></o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font
color=blue><span style='color:blue'>for</span></font>(x=1;;x++)<o:p></o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<o:p></o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font
color=green><span style='color:green'>// we need to handle the new scope so V8
knows when<o:p></o:p></span></font></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font
color=green><span style='color:green'>// it can re-use memory<o:p></o:p></span></font></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HandleScope
handle_scope;<o:p></o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font
color=green><span style='color:green'>// and we compile<o:p></o:p></span></font></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; script
= Script::Compile(source);<o:p></o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font
color=green><span style='color:green'>// and we execute<o:p></o:p></span></font></span></font></p>

<p class=MsoNormal style='text-autospace:none'><font size=2 face="Courier New"><span
lang=EN-GB style='font-size:10.0pt;font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result
= script-&gt;Run();<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span lang=EN-GB
style='font-size:10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span lang=EN-GB
style='font-size:10.0pt;font-family:Arial;color:navy'>Jan<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span lang=EN-GB
style='font-size:10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

</div>

</body>

</html>