|
| 1 | +\clause{Spawning tasks} |
| 2 | +\sclause{Task statements} |
| 3 | + |
| 4 | +\pnum |
| 5 | +The grammar of a statement (6.8, paragraph 1) |
| 6 | +\begin{cpp} |
| 7 | +(clause 6, paragraph 1) |
| 8 | +\end{cpp} |
| 9 | +is modified to add task-statement as a new alternative. |
| 10 | + |
| 11 | +\ssclause*{Syntax} |
| 12 | + |
| 13 | +\begin{bnf} |
| 14 | +\nontermdef{task-statement} |
| 15 | +\br |
| 16 | +task-block-statement |
| 17 | +\br |
| 18 | +task-spawn-statement |
| 19 | +\br |
| 20 | +task-sync-statement |
| 21 | +\br |
| 22 | +task-call-statement |
| 23 | +\end{bnf} |
| 24 | + |
| 25 | +\sclause{The task block statement} |
| 26 | +\ssclause*{Syntax} |
| 27 | + |
| 28 | +\begin{bnf} |
| 29 | +\nontermdef{task-block-statement} |
| 30 | +\br |
| 31 | +\terminal{_Task_parallel} \terminal{_Block} compound-statement |
| 32 | +\end{bnf} |
| 33 | + |
| 34 | +\ssclause*{Semantics} |
| 35 | + |
| 36 | +\pnum |
| 37 | +Defines a task block, within which tasks can be spawned. |
| 38 | +At the end of the contained compound statement, |
| 39 | +all child tasks spawned directly or indirectly |
| 40 | +within the compound statement are |
| 41 | +\defn{joined}: |
| 42 | +the statement following the task block is not executed |
| 43 | +until all of the child tasks complete. |
| 44 | + |
| 45 | +\pnum |
| 46 | +For a given statement, the |
| 47 | +\defn{associated task block} |
| 48 | +is defined as follows. |
| 49 | +For a statement within a task spawn statement, |
| 50 | +there is no associated task block, |
| 51 | +except within a nested task block statement. |
| 52 | +For a statement within a task block statement, |
| 53 | +the associated task block is the smallest enclosing task block statement. |
| 54 | +Otherwise, for a statement within the body of a function |
| 55 | +declared with the spawning function specifier, |
| 56 | +the associated task block is the same as it was |
| 57 | +at the point of the task spawning call statement |
| 58 | +that invoked the spawning function. |
| 59 | +For statements in other contexts, |
| 60 | +there is no associated task block. |
| 61 | +\footnote{EN: |
| 62 | +Should a parallel loop implicitly establish its own task block? |
| 63 | +} |
| 64 | + |
| 65 | +\begin{note} |
| 66 | +Task blocks can be nested lexically and/or dynamically. |
| 67 | +Determination of the associated task block is a hybrid process: |
| 68 | +lexically within a function, |
| 69 | +and dynamically across calls to spawning functions.% |
| 70 | +\footnote{DFEP: |
| 71 | +In Cilk, this determination can be done entirely lexically. |
| 72 | +In OpenMP, this determination can be done entirely dynamically. |
| 73 | +} |
| 74 | +Code designated for execution in another thread |
| 75 | +by means other than a task statement |
| 76 | +(e.g. using |
| 77 | +\tcode{thrd_create}) |
| 78 | +is not part of any task block. |
| 79 | +\end{note} |
| 80 | + |
| 81 | +\sclause{The task spawn statement} |
| 82 | +\ssclause*{Syntax} |
| 83 | + |
| 84 | +\begin{bnf} |
| 85 | +\nontermdef{task-spawn-statement} |
| 86 | +\br |
| 87 | +\terminal{_Task_parallel} \terminal{_Spawn} compound-statement |
| 88 | +\end{bnf} |
| 89 | + |
| 90 | +\ssclause*{Constraints} |
| 91 | + |
| 92 | +\pnum |
| 93 | +A task spawn statement shall have an associated task block. |
| 94 | + |
| 95 | +\ssclause*{Semantics} |
| 96 | +\pnum |
| 97 | +Creates a child task of the associated task block |
| 98 | +of the task spawn statement, |
| 99 | +in which the contained compound statement is executed. |
| 100 | +The execution of the task is unsequenced |
| 101 | +with respect to the statements of the associated task block |
| 102 | +following the spawn statement. |
| 103 | +The completion of the task synchronizes |
| 104 | +with the completion of the associated task block, |
| 105 | +or with the next execution of a sync statement |
| 106 | +within the associated task block. |
| 107 | + |
| 108 | +\sclause{The task sync statement} |
| 109 | +\ssclause*{Syntax} |
| 110 | + |
| 111 | +\begin{bnf} |
| 112 | +\nontermdef{task-sync-statement} |
| 113 | +\br |
| 114 | +\terminal{_Task_parallel} \terminal{_Sync} \terminal{;} |
| 115 | +\end{bnf} |
| 116 | + |
| 117 | +\ssclause*{Constraints} |
| 118 | + |
| 119 | +\pnum |
| 120 | +A task sync statement shall have an associated task block. |
| 121 | + |
| 122 | +\ssclause*{Semantics} |
| 123 | +\pnum |
| 124 | +Joins all child tasks of the associated task block |
| 125 | +of the task sync statement. |
| 126 | + |
| 127 | +\sclause{The task spawning call statement} |
| 128 | +\ssclause*{Syntax} |
| 129 | +\begin{bnf} |
| 130 | +\nontermdef{task-call-statement} |
| 131 | +\br |
| 132 | +\terminal{_Task_parallel} \terminal{_Call} expression-statement |
| 133 | +\footnote{EN: |
| 134 | +Using the same keyword pair |
| 135 | +for the statement prefix and the function specifier |
| 136 | +introduces a case where three tokens of lookahead |
| 137 | +(and hopefully no more) |
| 138 | +are sometimes needed |
| 139 | +to disambiguate a declaration from a statement. |
| 140 | +Is this what we want? |
| 141 | +} |
| 142 | +\end{bnf} |
| 143 | +\ssclause*{Constraints} |
| 144 | + |
| 145 | +\pnum |
| 146 | +A task spawning call statement shall have an associated task block. |
| 147 | + |
| 148 | +\ssclause*{Semantics} |
| 149 | + |
| 150 | +\pnum |
| 151 | +The contained expression statement is executed normally. |
| 152 | +Any called spawning function is allowed to spawn tasks; |
| 153 | +any such tasks are associated with the associated task block |
| 154 | +of the task spawning call statement, |
| 155 | +and are unsequenced with respect to the statements of the task block |
| 156 | +following the task spawning call statement. |
| 157 | + |
| 158 | +\sclause{The spawning function specifier} |
| 159 | +\ssclause*{Syntax} |
| 160 | +\pnum |
| 161 | +A new alternative is added to the grammar of function specifier |
| 162 | +(6.7.4 paragraph 1): |
| 163 | + |
| 164 | +\begin{bnf} |
| 165 | +\nontermdef{function-specifier} |
| 166 | +\br |
| 167 | +\terminal{_Task_parallel} \terminal{_Call} |
| 168 | +\end{bnf} |
| 169 | + |
| 170 | +\ssclause*{Constraints} |
| 171 | +\pnum |
| 172 | +If a spawning function specifier appears |
| 173 | +on any declaration of a function, |
| 174 | +it shall appear on every declaration of that function. |
| 175 | +A function declared with a spawning function specifier |
| 176 | +shall be called only from a task spawning call statement. |
| 177 | +\footnote{EN: |
| 178 | +Is a spawning function specifier part of the function's type? |
| 179 | +If so, are function-pointer conversions allowed? |
| 180 | +} |
0 commit comments