<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>MultiCore1.HC</title>
		<link rel="stylesheet" href="/style/templeos.css">
		<script src="/script/templeos.js" defer></script>
	</head>
	<body class="BG-15 FG-0 ">
		#define NUM	100<br>
<br>
I64 mp_not_done_flags,grand_total;<br>
<br>
U0 MPRoutine(CDoc *doc)<br>
{<br>
  I64 i,sum=0,<br>
	lo=NUM*Gs-&gt;num/mp_cnt,		//This is how to divide a job<br>
	hi=NUM*(Gs-&gt;num+1)/mp_cnt;<br>
  for (i=lo;i&lt;hi;i++)<br>
    sum+=i;<br>
  DocPrint(doc,"Core#%d:%d-%d:%d\n",Gs-&gt;num,lo,hi-1,sum);<br>
  lock {grand_total+=sum;}<br>
  LBtr(&amp;mp_not_done_flags,Gs-&gt;num);<br>
}<br>
<br>
U0 Main()<br>
{<br>
  I64 i;<br>
  grand_total=0;<br>
  mp_not_done_flags=1&lt;&lt;mp_cnt-1;<br>
  for (i=0;i&lt;mp_cnt;i++)<br>
    Spawn(&amp;MPRoutine,DocPut,NULL,i);<br>
  while (mp_not_done_flags)<br>
    Yield;<br>
  "Grand total:%d\n",grand_total;<br>
}<br>
<br>
Main;<br>

	</body>
</html>