diff options
-rw-r--r-- | docs/index.html | 98 |
1 files changed, 88 insertions, 10 deletions
diff --git a/docs/index.html b/docs/index.html index 116fc0a..3dfac70 100644 --- a/docs/index.html +++ b/docs/index.html | |||
@@ -38,6 +38,7 @@ | |||
38 | <a href="#description">Description</a> · | 38 | <a href="#description">Description</a> · |
39 | <a href="#systems">Supported systems</a> · | 39 | <a href="#systems">Supported systems</a> · |
40 | <a href="#installing">Building and Installing</a> · | 40 | <a href="#installing">Building and Installing</a> · |
41 | <a href="#apicheatsheet">API Cheat sheet</a> | ||
41 | <a href="#embedding">Embedding</a> | 42 | <a href="#embedding">Embedding</a> |
42 | </p> | 43 | </p> |
43 | 44 | ||
@@ -70,7 +71,7 @@ | |||
70 | </p> | 71 | </p> |
71 | 72 | ||
72 | <p> | 73 | <p> |
73 | This document was revised on 18-Apr-25, and applies to version <tt>4.0.0</tt>. | 74 | This document was revised on 21-Apr-25, and applies to version <tt>4.0.0</tt>. |
74 | </p> | 75 | </p> |
75 | </font> | 76 | </font> |
76 | </center> | 77 | </center> |
@@ -169,6 +170,82 @@ | |||
169 | </pre> | 170 | </pre> |
170 | 171 | ||
171 | 172 | ||
173 | <!-- API reference +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
174 | <hr/> | ||
175 | <h2 id="apicheatsheet">API Cheat sheet</h2> | ||
176 | <ul> | ||
177 | <li> | ||
178 | <tt>require "lanes"</tt>: to require Lanes | ||
179 | </li> | ||
180 | <li> | ||
181 | The <tt>lanes</tt> module | ||
182 | <ul> | ||
183 | <li><tt>lanes.cancel_error</tt>: a special error value returned from cancelled lanes</li> | ||
184 | <li><tt>lanes.collectgarbage()</tt>: o trigger a GC cycle in all Keeper states</li> | ||
185 | <li><tt>lanes.configure()</tt>: to configure Lanes</li> | ||
186 | <li><tt>lanes.coro()</tt>: to start a coroutine-like lane</li> | ||
187 | <li><tt>lanes.finally()</tt>: to install a function called on Lanes shutdown</li> | ||
188 | <li><tt>lanes.gen()</tt>: to start a lane as a regular function</li> | ||
189 | <li><tt>lanes.genactomic()</tt>: to obtain an atomic counter</li> | ||
190 | <li><tt>lanes.genlock()</tt>: to obtain an atomic-like data stack</li> | ||
191 | <li><tt>lanes.linda()</tt>: to create a Linda</li> | ||
192 | <li><tt>lanes.nameof()</tt>: to find where a value exists</li> | ||
193 | <li><tt>lanes.now_secs()</tt>: to obtain the current clock value</li> | ||
194 | <li><tt>lanes.register()</tt>: to scan modules so that functions using them can be transferred</li> | ||
195 | <li><tt>lanes.set_thread_priority()</tt>: to change thread priority</li> | ||
196 | <li><tt>lanes.set_thread_affinity()</tt>: to change thread affinity</li> | ||
197 | <li><tt>lanes.threads()</tt>: to obtain a list of all lanes</li> | ||
198 | <li><tt>lanes.sleep()</tt>: to sleep for a given duration</li> | ||
199 | <li><tt>lanes.timer()</tt>: to start a timer</li> | ||
200 | <li><tt>lanes.timers()</tt>: to list active timers</li> | ||
201 | </ul> | ||
202 | </li> | ||
203 | <li> | ||
204 | Given some lane handle <tt>lane_h</tt> | ||
205 | <ul> | ||
206 | <li><tt>lane_h[]</tt>: to wait for, and read the values returned by the lane</li> | ||
207 | <li><tt>lane_h:cancel()</tt>: to request the lane to stop running</li> | ||
208 | <li><tt>lane_h.error_trace_level</tt>: current setting of error logging level</li> | ||
209 | <li><tt>lane_h:get_threadname()</tt>: to read the thread name</li> | ||
210 | <li><tt>lane_h:join()</tt>: to wait for the lane to terminate (or yield)</li> | ||
211 | <li><tt>lane_h:resume()</tt>: to resume a coroutine Lane</li> | ||
212 | <li><tt>lane_h.status</tt>: current status of the lane</li> | ||
213 | </ul> | ||
214 | </li> | ||
215 | <li> | ||
216 | Inside the lane | ||
217 | <ul> | ||
218 | <li><tt>lane_threadname()</tt>: to read or change the name of the thread</li> | ||
219 | <li><tt>set_finalizer()</tt>: to install a function called when the lane exits</li> | ||
220 | </ul> | ||
221 | </li> | ||
222 | <li> | ||
223 | Given some Linda <tt>l</tt> | ||
224 | <ul> | ||
225 | <li><tt>l:cancel()</tt>: to mark a Linda for cancellation</li> | ||
226 | <li><tt>l:collectgarbage()</tt>: to trigger a GC cycle in the Linda's Keeper state</li> | ||
227 | <li><tt>l:deep()</tt>: returns a light userdata uniquely representing the Linda</li> | ||
228 | <li><tt>l:dump()</tt>: to have information about slot contents</li> | ||
229 | <li><tt>l:count()</tt>: to count data items</li> | ||
230 | <li><tt>l:get()</tt>: to read data without consuming it</li> | ||
231 | <li><tt>l:limit()</tt>: to cap the amount of transiting data</li> | ||
232 | <li><tt>l:receive()</tt>: to read one item of data from multiple slots</li> | ||
233 | <li><tt>l:receive_batched()</tt>: to to read several item of data from a single slot</li> | ||
234 | <li><tt>l:restrict()</tt>: to place a restraint on the operations that can be done</li> | ||
235 | <li><tt>l:send()</tt>: to append data</li> | ||
236 | <li><tt>l:set()</tt>: to replace the data</li> | ||
237 | <li><tt>l:wake()</tt>: to manually wake blocking calls</li> | ||
238 | </ul> | ||
239 | </li> | ||
240 | <li> | ||
241 | embedding | ||
242 | <ul> | ||
243 | <li><tt>luaopen_lanes_embedded</tt>: to manually initialize Lanes</li> | ||
244 | </ul> | ||
245 | </li> | ||
246 | </ul> | ||
247 | |||
248 | |||
172 | <!-- embedding +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 249 | <!-- embedding +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
173 | <hr/> | 250 | <hr/> |
174 | <h2 id="embedding">Embedding</h2> | 251 | <h2 id="embedding">Embedding</h2> |
@@ -1137,14 +1214,17 @@ | |||
1137 | </pre></td></tr></table> | 1214 | </pre></td></tr></table> |
1138 | 1215 | ||
1139 | <p> | 1216 | <p> |
1140 | <tt>timeout</tt> is an optional number >= 0. Defaults to infinite if left unspecified or <tt>nil</tt>. | ||
1141 | <br /> | ||
1142 | <tt>cancel()</tt> sends a cancellation request to the lane. | 1217 | <tt>cancel()</tt> sends a cancellation request to the lane. |
1143 | <br /> | 1218 | <p> |
1144 | First argument is a <tt>mode</tt> can be one of: | 1219 | Returns <tt>true, lane_h.status</tt> if lane was already done (in <tt>"done"</tt>, <tt>"error"</tt> or <tt>"cancelled"</tt> status), or the cancellation was fruitful within <tt>timeout_secs</tt> timeout period.<br /> |
1220 | Returns <tt>false, "timeout"</tt> otherwise. | ||
1221 | </p> | ||
1222 | First argument is a <tt>mode</tt>. It can be one of: | ||
1145 | <ul> | 1223 | <ul> |
1146 | <li> | 1224 | <li> |
1147 | <tt>"soft"</tt>: Cancellation will only cause <tt>cancel_test()</tt> to return <tt>true</tt>, so that the lane can cleanup manually. | 1225 | <tt>"soft"</tt>: Cancellation will only cause <tt>cancel_test()</tt> to return <tt>true</tt>, so that the lane can cleanup manually. |
1226 | <br /> | ||
1227 | Lindas will also check for cancellation inside blocking calls to early out based on their <tt>wake_period</tt>. | ||
1148 | </li> | 1228 | </li> |
1149 | <li> | 1229 | <li> |
1150 | <tt>"hard"</tt>: waits for the request to be processed, or a timeout to occur. <a href="#lindas">linda</a> operations detecting the cancellation request will raise a special cancellation error (meaning they won't return in that case).<br /> | 1230 | <tt>"hard"</tt>: waits for the request to be processed, or a timeout to occur. <a href="#lindas">linda</a> operations detecting the cancellation request will raise a special cancellation error (meaning they won't return in that case).<br /> |
@@ -1160,15 +1240,13 @@ | |||
1160 | If <tt>mode</tt> is not specified, it defaults to <tt>"hard"</tt>. | 1240 | If <tt>mode</tt> is not specified, it defaults to <tt>"hard"</tt>. |
1161 | If <tt>wake_lane</tt> is <tt>true</tt>, the lane is also signalled so that execution returns from any pending <a href="#lindas">linda</a> operation. <a href="#lindas">linda</a> operations detecting the cancellation request return <tt>lanes.cancel_error</tt>. | 1241 | If <tt>wake_lane</tt> is <tt>true</tt>, the lane is also signalled so that execution returns from any pending <a href="#lindas">linda</a> operation. <a href="#lindas">linda</a> operations detecting the cancellation request return <tt>lanes.cancel_error</tt>. |
1162 | </p> | 1242 | </p> |
1163 | <p> | 1243 | <tt>timeout</tt> is an optional number >= 0. Defaults to infinite if left unspecified or <tt>nil</tt>. |
1164 | Returns <tt>true, lane_h.status</tt> if lane was already done (in <tt>"done"</tt>, <tt>"error"</tt> or <tt>"cancelled"</tt> status), or the cancellation was fruitful within <tt>timeout_secs</tt> timeout period.<br /> | 1244 | <br /> |
1165 | Returns <tt>false, "timeout"</tt> otherwise. | ||
1166 | </p> | ||
1167 | <p> | 1245 | <p> |
1168 | If the lane is still running after the timeout expired, there is a chance lanes will freeze forever at shutdown when failing to terminate all free-running lanes within the specified timeout. | 1246 | If the lane is still running after the timeout expired, there is a chance lanes will freeze forever at shutdown when failing to terminate all free-running lanes within the specified timeout. |
1169 | </p> | 1247 | </p> |
1170 | <p> | 1248 | <p> |
1171 | Cancellation is tested <u>before</u> going to sleep in <tt>receive()</tt> or <tt>send()</tt> calls and after executing <tt>cancelstep</tt> Lua statements. A pending <tt>receive()</tt>or <tt>send()</tt> call is awakened. | 1249 | Cancellation is tested <u>before</u> going to sleep in <tt>receive()</tt>, <tt>receive_batched()</tt> or <tt>send()</tt> calls and after executing <tt>cancelstep</tt> Lua statements. A pending <tt>receive()</tt>or <tt>send()</tt> call is awakened. |
1172 | <br /> | 1250 | <br /> |
1173 | This means the execution of the lane will resume although the operation has not completed, to give the lane a chance to detect cancellation (even in the case the code waits on a <a href="#lindas">linda</a> with infinite timeout). | 1251 | This means the execution of the lane will resume although the operation has not completed, to give the lane a chance to detect cancellation (even in the case the code waits on a <a href="#lindas">linda</a> with infinite timeout). |
1174 | <br /> | 1252 | <br /> |