<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/functional.parallel.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'parallel.run.php',
    1 => 'parallel\\run',
    2 => 'Execution',
  ),
  'up' => 
  array (
    0 => 'functional.parallel.php',
    1 => 'Functional API',
  ),
  'prev' => 
  array (
    0 => 'parallel.bootstrap.php',
    1 => 'parallel\\bootstrap',
  ),
  'next' => 
  array (
    0 => 'class.parallel-runtime.php',
    1 => 'parallel\\Runtime',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/parallel/functions/parallel.run.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="parallel.run" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">parallel\run</h1>
  <p class="verinfo">(1.0.0)</p><p class="refpurpose"><span class="refname">parallel\run</span> &mdash; <span class="dc-title">Execution</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-parallel.run-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>parallel\run</strong></span>(<span class="methodparam"><span class="type"><a href="class.closure.php" class="type Closure">Closure</a></span> <code class="parameter">$task</code></span>): <span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type">Future</span></span></div>

  <p class="simpara">
   Shall schedule <code class="parameter">task</code> for execution in parallel.
  </p>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>parallel\run</strong></span>(<span class="methodparam"><span class="type"><a href="class.closure.php" class="type Closure">Closure</a></span> <code class="parameter">$task</code></span>, <span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$argv</code></span>): <span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type">Future</span></span></div>

  <p class="simpara">
   Shall schedule <code class="parameter">task</code> for execution in parallel, passing <code class="parameter">argv</code> at execution time.
  </p>
 </div>


 <div class="refsect1 scheduling-characteristics" id="refsect1-parallel.run-scheduling-characteristics">
  <h3 class="title">Automatic Scheduling</h3>
  <p class="simpara">
   If a <span class="classname"><a href="class.parallel-runtime.php" class="classname">\parallel\Runtime</a></span> internally created and cached by a previous call to <span class="function"><strong>parallel\run()</strong></span> is idle,
   it will be used to execute the task. If no <span class="classname"><a href="class.parallel-runtime.php" class="classname">\parallel\Runtime</a></span> is idle parallel will create and cache a
   <span class="classname"><a href="class.parallel-runtime.php" class="classname">\parallel\Runtime</a></span>.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    <span class="classname"><a href="class.parallel-runtime.php" class="classname">\parallel\Runtime</a></span> objects created by the programmer are not used for automatic scheduling.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-parallel.run-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">task</code></dt>
    <dd>
     <span class="simpara">
      A <span class="classname"><a href="class.closure.php" class="classname">Closure</a></span> with specific characteristics.
     </span>
    </dd>
   
   
    <dt><code class="parameter">argv</code></dt>
    <dd>
     <span class="simpara">
      An <span class="type"><a href="language.types.array.php" class="type array">array</a></span> of arguments with specific characteristics to be passed to <code class="parameter">task</code> at execution time.
     </span>
    </dd>
   
  </dl>
 </div>

 <div class="refsect1 closure-characteristics" id="refsect1-parallel.run-closure-characteristics">
 <h3 class="title">Task Characteristics</h3>
 <p class="para">
  Closures scheduled for parallel execution must not:
  <ul class="simplelist">
   <li>accept or return by reference</li>
   <li>accept or return internal objects (see notes)</li>
   <li>execute a limited set of instructions</li>
  </ul>
 </p>
 <p class="para">
  Instructions prohibited in Closures intended for parallel execution are:
  <ul class="simplelist">
   <li>yield</li>
   <li>use by-reference</li>
   <li>declare class</li>
   <li>declare named function</li>
  </ul>
 </p>
 <blockquote class="note"><p><strong class="note">Note</strong>: 
  <span class="simpara">
   Nested closures may yield or use by-reference, but must not contain class or named function declarations.
  </span>
 </p></blockquote>
 <blockquote class="note"><p><strong class="note">Note</strong>: 
  <span class="simpara">
   No instructions are prohibited in the files which the task may include.
  </span>
 </p></blockquote>
 </div>

 <div class="refsect1 argv-characteristics" id="refsect1-parallel.run-argv-characteristics">
 <h3 class="title">Arguments Characteristics</h3>
 <p class="para">
  Arguments must not:
  <ul class="simplelist">
   <li>contain references</li>
   <li>contain resources</li>
   <li>contain internal objects (see notes)</li>
  </ul>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    In the case of file stream resources, the resource will be cast to the file descriptor and passed as <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> where possible, this is unsupported on Windows.
   </span>
  </p></blockquote>
 </p>
 </div>

 <div class="refsect1 object-characteristics" id="refsect1-parallel.run-object-characteristics">
  <h3 class="title">Internal Objects Notes</h3>
  <p class="simpara">
   Internal objects generally use a custom structure which cannot be copied by value safely, PHP currently lacks the mechanics to do this (without serialization)
   and so only objects that do not use a custom structure may be shared.
  </p>
  <p class="simpara">
   Some internal objects do not use a custom structure, for example <span class="classname"><a href="class.parallel-events-event.php" class="classname">parallel\Events\Event</a></span> and so may be shared.
  </p>
  <p class="simpara">
   Closures are a special kind of internal object and support being copied by value, and so may be shared.
  </p>
  <p class="simpara">
   Channels are central to writing parallel code and support concurrent access and execution by necessity, and so may be shared.
  </p>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="simpara">
    A user class that extends an internal class may use a custom structure as defined by the internal class, in which case they cannot be copied by value safely,
    and so may not be shared.
   </p>
  </div>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-parallel.run-returnvalues">
  <h3 class="title">Return Values</h3>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="simpara">
    The return <span class="type"><a href="class.parallel-future.php" class="type parallel\Future">parallel\Future</a></span> must not be ignored when the task contains a return or throw statement.
   </p>
  </div>
 </div>

 <div class="refsect1 exceptions" id="refsect1-parallel.run-exceptions">
  <h3 class="title">Exceptions</h3>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="simpara">
    Shall throw <span class="type">parallel\Runtime\Error\Closed</span> if <span class="type"><a href="class.parallel-runtime.php" class="type parallel\Runtime">parallel\Runtime</a></span> was closed.
   </p>
  </div>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="simpara">
    Shall throw <span class="type">parallel\Runtime\Error\IllegalFunction</span> if <code class="parameter">task</code> is a closure created from an internal function.
   </p>
  </div>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="simpara">
    Shall throw <span class="type">parallel\Runtime\Error\IllegalInstruction</span> if <code class="parameter">task</code> contains illegal instructions.
   </p>
  </div>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="simpara">
    Shall throw <span class="type">parallel\Runtime\Error\IllegalParameter</span> if <code class="parameter">task</code> accepts or <code class="parameter">argv</code> contains illegal variables.
   </p>
  </div>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="simpara">
    Shall throw <span class="type">parallel\Runtime\Error\IllegalReturn</span> if <code class="parameter">task</code> returns illegally.
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-parallel.run-seealso">
   <h3 class="title">See Also</h3>
   <ul class="simplelist">
    <li><a href="parallel-runtime.run.php" class="xref">parallel\Runtime::run</a></li>
   </ul>
  </div>


</div><?php manual_footer($setup); ?>