diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-05-14 16:04:45 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-05-14 16:04:45 -0700 |
commit | 65361948ca7975553757a0e0df4ac7352413044c (patch) | |
tree | 22063c089f67cb0d82623f2edc2c16b7e4389d41 /html/039wait.cc.html | |
parent | 64586540eccbc0880341782d329b419ab9d002de (diff) | |
download | mu-65361948ca7975553757a0e0df4ac7352413044c.tar.gz |
1376 - update github docs
Diffstat (limited to 'html/039wait.cc.html')
-rw-r--r-- | html/039wait.cc.html | 106 |
1 files changed, 74 insertions, 32 deletions
diff --git a/html/039wait.cc.html b/html/039wait.cc.html index feb7e536..687cd207 100644 --- a/html/039wait.cc.html +++ b/html/039wait.cc.html @@ -2,7 +2,7 @@ <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - 039wait.cc</title> +<title>~/Desktop/s/mu/039wait.cc</title> <meta name="Generator" content="Vim/7.4"> <meta name="plugin-version" content="vim7.4_v1"> <meta name="syntax" content="cpp"> @@ -14,11 +14,12 @@ pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background- body { font-family: monospace; color: #d0d0d0; background-color: #000000; } * { font-size: 1em; } .cSpecial { color: #008000; } +.Identifier { color: #008080; } .Constant { color: #008080; } .Comment { color: #8080ff; } .Delimiter { color: #c000c0; } .Special { color: #ff6060; } -.Identifier { color: #008080; } +.CommentedCode { color: #6c6c6c; } .traceContains { color: #008000; } --> </style> @@ -38,14 +39,14 @@ body { font-family: monospace; color: #d0d0d0; background-color: #000000; } <span class="Delimiter">:(scenario wait_for_location)</span> recipe f1 [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal start-running f2:recipe - wait-for-location <span class="Constant">1</span>:integer + wait-for-location <span class="Constant">1</span>:number <span class="Comment"># now wait for f2 to run and modify location 1 before using its value</span> - <span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:integer + <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number ] recipe f2 [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal ] <span class="Comment"># if we got the synchronization wrong we'd be storing 0 in location 2</span> <span class="traceContains">+mem: storing 34 in location 2</span> @@ -57,9 +58,9 @@ WAITING<span class="Delimiter">,</span> <span class="Delimiter">:(before "End routine Fields")</span> <span class="Comment">// only if state == WAITING</span> index_t waiting_on_location<span class="Delimiter">;</span> -int old_value_of_wating_location<span class="Delimiter">;</span> +int old_value_of_waiting_location<span class="Delimiter">;</span> <span class="Delimiter">:(before "End routine Constructor")</span> -waiting_on_location = old_value_of_wating_location = <span class="Constant">0</span><span class="Delimiter">;</span> +waiting_on_location = old_value_of_waiting_location = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">//: primitive recipe to put routines in that state</span> @@ -69,11 +70,12 @@ WAIT_FOR_LOCATION<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"wait-for-location"</span>] = WAIT_FOR_LOCATION<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case WAIT_FOR_LOCATION: <span class="Delimiter">{</span> - reagent loc = canonize<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> + reagent loc = canonize<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> Current_routine<span class="Delimiter">-></span>state = WAITING<span class="Delimiter">;</span> Current_routine<span class="Delimiter">-></span>waiting_on_location = loc<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - Current_routine<span class="Delimiter">-></span>old_value_of_wating_location = Memory[loc<span class="Delimiter">.</span>value]<span class="Delimiter">;</span> + Current_routine<span class="Delimiter">-></span>old_value_of_waiting_location = Memory[loc<span class="Delimiter">.</span>value]<span class="Delimiter">;</span> trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"waiting for location "</span> << loc<span class="Delimiter">.</span>value << <span class="Constant">" to change from "</span> << Memory[loc<span class="Delimiter">.</span>value]<span class="Delimiter">;</span> +<span class="CommentedCode">//? trace("schedule") << Current_routine->id << ": waiting for location " << loc.value << " to change from " << Memory[loc.value]; //? 2</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> @@ -81,28 +83,38 @@ case WAIT_FOR_LOCATION: <span class="Delimiter">{</span> <span class="Delimiter">:(before "End Scheduler State Transitions")</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Routines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>Routines[i]<span class="Delimiter">-></span>state != WAITING<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>Memory[Routines[i]<span class="Delimiter">-></span>waiting_on_location] && - Memory[Routines[i]<span class="Delimiter">-></span>waiting_on_location] != Routines[i]<span class="Delimiter">-></span>old_value_of_wating_location<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="CommentedCode">//? trace("schedule") << "wake up loop 1: routine " << Routines.at(i)->id << " has state " << Routines.at(i)->state; //? 1</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state != WAITING<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span class="CommentedCode">//? trace("schedule") << "waiting on location: " << Routines.at(i)->waiting_on_location; //? 1</span> +<span class="CommentedCode">//? if (Routines.at(i)->waiting_on_location) //? 2</span> +<span class="CommentedCode">//? trace("schedule") << "checking routine " << Routines.at(i)->id << " waiting on location " //? 2</span> +<span class="CommentedCode">//? << Routines.at(i)->waiting_on_location << ": " << Memory[Routines.at(i)->waiting_on_location] << " vs " << Routines.at(i)->old_value_of_waiting_location; //? 2</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>waiting_on_location && + Memory[Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>waiting_on_location] != Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>old_value_of_waiting_location<span class="Delimiter">)</span> <span class="Delimiter">{</span> trace<span class="Delimiter">(</span><span class="Constant">"schedule"</span><span class="Delimiter">)</span> << <span class="Constant">"waking up routine</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> - Routines[i]<span class="Delimiter">-></span>state = RUNNING<span class="Delimiter">;</span> - Routines[i]<span class="Delimiter">-></span>waiting_on_location = Routines[i]<span class="Delimiter">-></span>old_value_of_wating_location = <span class="Constant">0</span><span class="Delimiter">;</span> + Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state = RUNNING<span class="Delimiter">;</span> + Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>waiting_on_location = Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>old_value_of_waiting_location = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> -<span class="Comment">//: also allow waiting on a routine</span> +<span class="Comment">//: also allow waiting on a routine to stop running</span> <span class="Delimiter">:(scenario wait_for_routine)</span> recipe f1 [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal - <span class="Constant">2</span>:integer/routine<span class="Special"> <- </span>start-running f2:recipe - wait-for-routine <span class="Constant">2</span>:integer/routine + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">0</span>:literal + <span class="Constant">12</span>:number/routine<span class="Special"> <- </span>start-running f2:recipe + wait-for-routine <span class="Constant">12</span>:number/routine <span class="Comment"># now wait for f2 to run and modify location 1 before using its value</span> - <span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:integer + <span class="Constant">3</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number ] recipe f2 [ - <span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal + <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal ] +<span class="traceContains">+schedule: f1</span> +<span class="traceContains">+run: waiting for routine 2</span> +<span class="traceContains">+schedule: f2</span> +<span class="traceContains">+schedule: waking up routine 1</span> +<span class="traceContains">+schedule: f1</span> <span class="Comment"># if we got the synchronization wrong we'd be storing 0 in location 3</span> <span class="traceContains">+mem: storing 34 in location 3</span> @@ -118,28 +130,58 @@ WAIT_FOR_ROUTINE<span class="Delimiter">,</span> Recipe_number[<span class="Constant">"wait-for-routine"</span>] = WAIT_FOR_ROUTINE<span class="Delimiter">;</span> <span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> case WAIT_FOR_ROUTINE: <span class="Delimiter">{</span> - reagent loc = canonize<span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients[<span class="Constant">0</span>]<span class="Delimiter">);</span> Current_routine<span class="Delimiter">-></span>state = WAITING<span class="Delimiter">;</span> - Current_routine<span class="Delimiter">-></span>waiting_on_routine = loc<span class="Delimiter">.</span>value<span class="Delimiter">;</span> - trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"waiting for routine "</span> << loc<span class="Delimiter">.</span>value<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>size<span class="Delimiter">()</span> == <span class="Constant">1</span><span class="Delimiter">);</span> <span class="Comment">// scalar</span> + Current_routine<span class="Delimiter">-></span>waiting_on_routine = ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> + trace<span class="Delimiter">(</span><span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"waiting for routine "</span> << ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(before "End Scheduler State Transitions")</span> +<span class="Comment">// Wake up any routines waiting for other routines to go to sleep.</span> +<span class="Comment">// Important: this must come after the scheduler loop above giving routines</span> +<span class="Comment">// waiting for locations to change a chance to wake up.</span> for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Routines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>Routines[i]<span class="Delimiter">-></span>state != WAITING<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - if <span class="Delimiter">(</span>!Routines[i]<span class="Delimiter">-></span>waiting_on_routine<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> - index_t id = Routines[i]<span class="Delimiter">-></span>waiting_on_routine<span class="Delimiter">;</span> - assert<span class="Delimiter">(</span>id != i<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state != WAITING<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>!Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>waiting_on_routine<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + index_t id = Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>waiting_on_routine<span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>id != Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>id<span class="Delimiter">);</span> for <span class="Delimiter">(</span>index_t j = <span class="Constant">0</span><span class="Delimiter">;</span> j < Routines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> - if <span class="Delimiter">(</span>Routines[j]<span class="Delimiter">-></span>id == id && Routines[j]<span class="Delimiter">-></span>state != WAITING<span class="Delimiter">)</span> <span class="Delimiter">{</span> - trace<span class="Delimiter">(</span><span class="Constant">"schedule"</span><span class="Delimiter">)</span> << <span class="Constant">"waking up routine</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> - Routines[i]<span class="Delimiter">-></span>state = RUNNING<span class="Delimiter">;</span> - Routines[i]<span class="Delimiter">-></span>waiting_on_routine = <span class="Constant">0</span><span class="Delimiter">;</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">)-></span>id == id && Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">)-></span>state != RUNNING<span class="Delimiter">)</span> <span class="Delimiter">{</span> + trace<span class="Delimiter">(</span><span class="Constant">"schedule"</span><span class="Delimiter">)</span> << <span class="Constant">"waking up routine "</span> << Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>id<span class="Delimiter">;</span> + Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state = RUNNING<span class="Delimiter">;</span> + Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>waiting_on_routine = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> <span class="Delimiter">}</span> +<span class="Delimiter">:(before "End Primitive Recipe Declarations")</span> +SWITCH<span class="Delimiter">,</span> +<span class="Delimiter">:(before "End Primitive Recipe Numbers")</span> +Recipe_number[<span class="Constant">"switch"</span>] = SWITCH<span class="Delimiter">;</span> +<span class="Delimiter">:(before "End Primitive Recipe Implementations")</span> +case SWITCH: <span class="Delimiter">{</span> + index_t id = some_other_running_routine<span class="Delimiter">();</span> + if <span class="Delimiter">(</span>id<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>id != Current_routine<span class="Delimiter">-></span>id<span class="Delimiter">);</span> +<span class="CommentedCode">//? cerr << "waiting on " << id << " from " << Current_routine->id << '\n'; //? 1</span> + Current_routine<span class="Delimiter">-></span>state = WAITING<span class="Delimiter">;</span> + Current_routine<span class="Delimiter">-></span>waiting_on_routine = id<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Identifier">break</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> + +<span class="Delimiter">:(code)</span> +index_t some_other_running_routine<span class="Delimiter">()</span> <span class="Delimiter">{</span> + for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < Routines<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> + if <span class="Delimiter">(</span>i == Current_routine_index<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> + assert<span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> != Current_routine<span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>id != Current_routine<span class="Delimiter">-></span>id<span class="Delimiter">);</span> + if <span class="Delimiter">(</span>Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>state == RUNNING<span class="Delimiter">)</span> + <span class="Identifier">return</span> Routines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)-></span>id<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span class="Delimiter">}</span> </pre> </body> </html> |