diff options
Diffstat (limited to 'docs')
-rw-r--r-- | docs/index.html | 214 |
1 files changed, 186 insertions, 28 deletions
diff --git a/docs/index.html b/docs/index.html index ba25515..72e91ba 100644 --- a/docs/index.html +++ b/docs/index.html | |||
@@ -54,9 +54,9 @@ | |||
54 | <a href="#changes">Change log</a> | 54 | <a href="#changes">Change log</a> |
55 | <!-- ... --> | 55 | <!-- ... --> |
56 | 56 | ||
57 | <p><br/><font size="-1"><i>Copyright © 2007-11 Asko Kauppi. All rights reserved.</i> | 57 | <p><br/><font size="-1"><i>Copyright © 2007-12 Asko Kauppi, Benoit Germain. All rights reserved.</i> |
58 | <br>Lua Lanes is published under the same <A HREF="http://en.wikipedia.org/wiki/MIT_License">MIT license</A> as Lua 5.1. | 58 | <br>Lua Lanes is published under the same <A HREF="http://en.wikipedia.org/wiki/MIT_License">MIT license</A> as Lua 5.1. |
59 | </p><p>This document was revised on 1-Mar-11, and applies to version 2.1.0. | 59 | </p><p>This document was revised on 17-Feb-11, and applies to version 3.1.0 |
60 | </font></p> | 60 | </font></p> |
61 | 61 | ||
62 | </center> | 62 | </center> |
@@ -162,6 +162,69 @@ Or use <A HREF="http://www.luarocks.org" TARGET="_blank">Lua Rocks</A> package m | |||
162 | 162 | ||
163 | <!-- launching +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 163 | <!-- launching +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
164 | <hr/> | 164 | <hr/> |
165 | |||
166 | <h2 id="initialization">Initialization</h2> | ||
167 | |||
168 | <p> | ||
169 | The following sample shows how to initialize the Lanes module. | ||
170 | </p> | ||
171 | |||
172 | <table border="1" bgcolor="#FFFFE0" width="500"> | ||
173 | <tr> | ||
174 | <td> | ||
175 | <pre> | ||
176 | local lanes = require "lanes".configure() | ||
177 | </pre> | ||
178 | </table> | ||
179 | |||
180 | <p> | ||
181 | Starting with version 3.0-beta, requiring the module follows Lua 5.2 rules: | ||
182 | the module is not available under the global name "lanes", but has to be accessed | ||
183 | through require's return value. | ||
184 | After lanes is required, it is necessary to call <tt>lanes.configure()</tt>, which is the | ||
185 | only function exposed by the module at this point. Calling <tt>configure()</tt> will | ||
186 | perform one-time initializations and make the rest of the API available. | ||
187 | At the same time, <tt>configure()</tt> itself will be replaced by another function that | ||
188 | raises an error if called again with differing arguments. | ||
189 | </p> | ||
190 | |||
191 | <p> | ||
192 | <table border="1" bgcolor="#E0E0FF" cellpadding="10"> | ||
193 | <tr> | ||
194 | <td> | ||
195 | <code> | ||
196 | lanes.configure( [opt_tbl]) | ||
197 | </code> | ||
198 | </table> | ||
199 | </p> | ||
200 | <p> | ||
201 | <tt>lanes.configure</tt> accepts an optional options table as sole argument. | ||
202 | <table> | ||
203 | <tr valign=top><td width=40></td><td> | ||
204 | <code>.nb_keepers</code> <br/><nobr>N</nobr></td><td width=40></td> | ||
205 | <td> | ||
206 | Controls the number of keeper states used internally by lindas to transfer data between lanes. (see below). Default is 1. | ||
207 | </td></tr> | ||
208 | |||
209 | <tr valign=top><td/><td> | ||
210 | <code>.with_timers</code> <br/>nil/false/anything</td><td/> | ||
211 | <td> | ||
212 | If equal to <tt>false</tt>, Lanes doesn't start the timer service, | ||
213 | and the associated API will be absent from the interface (see below). | ||
214 | Any other value (including <tt>nil</tt>), starts the timer service. | ||
215 | </td></tr> | ||
216 | |||
217 | <tr valign="top"> | ||
218 | <td/> | ||
219 | <td> | ||
220 | <code>.on_create_state</code> <br/>C function/nil | ||
221 | </td><td/> | ||
222 | <td> | ||
223 | If provided, will be called in every created Lua state (keepers and lanes) right after it is created, and *before* any library is loaded. | ||
224 | That way, all C functions it loads in the state can be added to the function lookup database. | ||
225 | </td> | ||
226 | </tr> | ||
227 | </table> | ||
165 | <h2 id="creation">Creation</h2> | 228 | <h2 id="creation">Creation</h2> |
166 | 229 | ||
167 | <p>The following sample shows preparing a function for parallel calling, and | 230 | <p>The following sample shows preparing a function for parallel calling, and |
@@ -172,7 +235,8 @@ joins the threads, waiting for any results not already there. | |||
172 | 235 | ||
173 | <table border=1 bgcolor="#FFFFE0" width=500><tr><td> | 236 | <table border=1 bgcolor="#FFFFE0" width=500><tr><td> |
174 | <pre> | 237 | <pre> |
175 | require "lanes" | 238 | local lanes = require "lanes" |
239 | lanes.configure() | ||
176 | 240 | ||
177 | f= lanes.gen( function(n) return 2*n end ) | 241 | f= lanes.gen( function(n) return 2*n end ) |
178 | a= f(1) | 242 | a= f(1) |
@@ -189,14 +253,14 @@ joins the threads, waiting for any results not already there. | |||
189 | lane_h= func( ... )</code> | 253 | lane_h= func( ... )</code> |
190 | </table> | 254 | </table> |
191 | </p> | 255 | </p> |
192 | </p><p> | 256 | <p> |
193 | The function returned by <tt>lanes.gen()</tt> is a "generator" for | 257 | The function returned by <tt>lanes.gen()</tt> is a "generator" for |
194 | launching any number of lanes. They will share code, options, initial globals, | 258 | launching any number of lanes. They will share code, options, initial globals, |
195 | but the particular arguments may vary. Only calling the generator function | 259 | but the particular arguments may vary. Only calling the generator function |
196 | actually launches a lane, and provides a handle for controlling it. | 260 | actually launches a lane, and provides a handle for controlling it. |
197 | Alternatively, <tt>lane_func</tt> may be a string, in which case it will be compiled | 261 | Alternatively, <tt>lane_func</tt> may be a string, in which case it will be compiled |
198 | in the lane. This is to be able to launch lanes whith LuaJIT, | 262 | in the lane. This was to be able to launch lanes with older versions of LuaJIT, |
199 | which does not support lua_dump, used internally to transfer functions to the lane. | 263 | which didn't not support lua_dump, used internally to transfer functions to the lane. |
200 | <!-- | 264 | <!-- |
201 | </p> | 265 | </p> |
202 | <p>This prepares <tt>lane_func</tt> to be called in parallel. It does not yet start | 266 | <p>This prepares <tt>lane_func</tt> to be called in parallel. It does not yet start |
@@ -212,19 +276,21 @@ also in the new lanes. | |||
212 | <code>libs_str</code> defines the standard libraries made available to the | 276 | <code>libs_str</code> defines the standard libraries made available to the |
213 | new Lua state: | 277 | new Lua state: |
214 | <table> | 278 | <table> |
215 | <tr><td/><td>(nothing)</td><td>no standard libraries (default)</td></tr> | 279 | <tr><td width=40></td><td>(nothing)</td><td width=40></td><td>no standard libraries (default)</td></tr> |
216 | <tr><td width=40><td><tt>"base"</tt> or <tt>""</tt></td> | 280 | <tr><td/> |
217 | <td>root level names, <tt>print</tt>, <tt>assert</tt>, <tt>unpack</tt> etc.</td></tr> | 281 | <td><tt>"base"</tt> or <tt>""</tt></td><td/> |
218 | <tr><td/><td><tt>"coroutine"</tt></td><td><tt>coroutine.*</tt> namespace <font size="-1">(part of base in Lua 5.1)</font></td></tr> | 282 | <td>root level names, <tt>print</tt>, <tt>assert</tt>, <tt>unpack</tt> etc.</td> |
219 | <tr><td/><td><tt>"debug"</tt></td><td><tt>debug.*</tt> namespace</td></tr> | 283 | </tr> |
220 | <tr><td/><td><tt>"io"</tt></td><td><tt>io.*</tt> namespace</td></tr> | 284 | <tr><td/><td><tt>"coroutine"</tt></td><td/><td><tt>coroutine.*</tt> namespace <font size="-1">(part of base in Lua 5.1)</font></td></tr> |
221 | <tr><td/><td><tt>"math"</tt></td><td><tt>math.*</tt> namespace</td></tr> | 285 | <tr><td/><td><tt>"debug"</tt></td><td/><td><tt>debug.*</tt> namespace</td></tr> |
222 | <tr><td/><td><tt>"os"</tt></td><td><tt>os.*</tt> namespace</td></tr> | 286 | <tr><td/><td><tt>"io"</tt></td><td/><td><tt>io.*</tt> namespace</td></tr> |
223 | <tr><td/><td><tt>"package"</tt></td><td><tt>package.*</tt> namespace and <tt>require</tt></td></tr> | 287 | <tr><td/><td><tt>"math"</tt></td><td/><td><tt>math.*</tt> namespace</td></tr> |
224 | <tr><td/><td><tt>"string"</tt></td><td><tt>string.*</tt> namespace</td></tr> | 288 | <tr><td/><td><tt>"os"</tt></td><td/><td><tt>os.*</tt> namespace</td></tr> |
225 | <tr><td/><td><tt>"table"</tt></td><td><tt>table.*</tt> namespace</td></tr> | 289 | <tr><td/><td><tt>"package"</tt></td><td/><td><tt>package.*</tt> namespace and <tt>require</tt></td></tr> |
290 | <tr><td/><td><tt>"string"</tt></td><td/><td><tt>string.*</tt> namespace</td></tr> | ||
291 | <tr><td/><td><tt>"table"</tt></td><td/><td><tt>table.*</tt> namespace</td></tr> | ||
226 | <br/> | 292 | <br/> |
227 | <tr><td/><td><tt>"*"</tt></td><td>all standard libraries</td></tr> | 293 | <tr><td/><td><tt>"*"</tt></td><td/><td>all standard libraries</td></tr> |
228 | </table> | 294 | </table> |
229 | 295 | ||
230 | </p><p> | 296 | </p><p> |
@@ -236,9 +302,9 @@ also in the new lanes. | |||
236 | lanes are run: | 302 | lanes are run: |
237 | </p><p> | 303 | </p><p> |
238 | <table> | 304 | <table> |
239 | <tr valign=top><td/><td> | 305 | <tr valign=top><td width=40></td><td> |
240 | <code>.cancelstep</code> <br/><nobr>N / true</nobr></td> | 306 | <code>.cancelstep</code> <br/><nobr>N / true</nobr></td> |
241 | <td> | 307 | <td width=40></td><td> |
242 | By default, lanes are only cancellable when they <u>enter</u> a pending | 308 | By default, lanes are only cancellable when they <u>enter</u> a pending |
243 | <tt>:receive()</tt> or <tt>:send()</tt> call. | 309 | <tt>:receive()</tt> or <tt>:send()</tt> call. |
244 | With this option, one can set cancellation check to occur every <tt>N</tt> | 310 | With this option, one can set cancellation check to occur every <tt>N</tt> |
@@ -247,7 +313,7 @@ also in the new lanes. | |||
247 | </td></tr> | 313 | </td></tr> |
248 | 314 | ||
249 | <tr valign=top><td/><td> | 315 | <tr valign=top><td/><td> |
250 | <code>.globals</code> <br/>globals_tbl</td> | 316 | <code>.globals</code> <br/>globals_tbl</td><td/> |
251 | <td> | 317 | <td> |
252 | Sets the globals table for the launched threads. This can be used for giving | 318 | Sets the globals table for the launched threads. This can be used for giving |
253 | them constants. | 319 | them constants. |
@@ -256,13 +322,40 @@ also in the new lanes. | |||
256 | modifying one will only affect the particular lane. | 322 | modifying one will only affect the particular lane. |
257 | </td></tr> | 323 | </td></tr> |
258 | 324 | ||
325 | <tr valign="top"> | ||
326 | <td/> | ||
327 | <td> | ||
328 | <code>.required</code> <br/>modules_tbl | ||
329 | </td><td/> | ||
330 | <td> | ||
331 | Lists modules that have to be required in order to be able to trasnfer | ||
332 | functions they exposed. Starting with Lanes 3.0-beta, non-Lua functions are | ||
333 | no longer copied by recreating a C closure from a C pointer, but are searched | ||
334 | in lookup tables. These tables are built from the modules listed here. <tt>required</tt> | ||
335 | must be a list of strings, each one being the name of a module to be required. | ||
336 | </td> | ||
337 | </tr> | ||
338 | |||
259 | <tr valign=top><td width=40><td> | 339 | <tr valign=top><td width=40><td> |
260 | <code>.priority</code> <br/><nobr>-2..+2</nobr></td> | 340 | <code>.priority</code> <br/><nobr>-2..+2</nobr></td><td/> |
261 | <td>The priority of lanes generated. -2 is lowest, +2 is highest. | 341 | <td>The priority of lanes generated. -2 is lowest, +2 is highest. |
262 | <br> | 342 | <br> |
263 | Implementation and dependability of priorities varies | 343 | Implementation and dependability of priorities varies |
264 | by platform. Especially Linux kernel 2.6 is not supporting priorities in user mode. | 344 | by platform. Especially Linux kernel 2.6 is not supporting priorities in user mode. |
265 | </td></tr> | 345 | </td></tr> |
346 | |||
347 | <tr valign="top"> | ||
348 | <td width="40"> | ||
349 | <td> | ||
350 | <code>.package</code><br/> | ||
351 | </td> | ||
352 | <td><td/> | ||
353 | <code>package</code> contents overrides, if needed. | ||
354 | Specifying it when <code>libs_str</code> doesn't cause the <code>package</code> library to be loaded will generate an error. | ||
355 | If not specified, the created lane will receive the current values of <tt>package</tt>. Only path, cpath, preload and loaders are transfered. | ||
356 | <br> | ||
357 | </td> | ||
358 | </tr> | ||
266 | </table> | 359 | </table> |
267 | <p>Each lane also gets a function <tt>set_debug_threadname()</tt> that it can use anytime to do as the name says. | 360 | <p>Each lane also gets a function <tt>set_debug_threadname()</tt> that it can use anytime to do as the name says. |
268 | Supported debuggers are Microsoft Visual Studio (for the C side) and Decoda (for the Lua side). | 361 | Supported debuggers are Microsoft Visual Studio (for the C side) and Decoda (for the Lua side). |
@@ -394,8 +487,9 @@ OS thread running the lane is forcefully killed. This means no GC, and should | |||
394 | generally be the last resort. | 487 | generally be the last resort. |
395 | </p> | 488 | </p> |
396 | <p>Cancellation is tested <u>before</u> going to sleep in <tt>receive()</tt> or <tt>send()</tt> calls | 489 | <p>Cancellation is tested <u>before</u> going to sleep in <tt>receive()</tt> or <tt>send()</tt> calls |
397 | and after executing <tt>cancelstep</tt> Lua statements. A currently pending <tt>receive()</tt> | 490 | and after executing <tt>cancelstep</tt> Lua statements. Starting with version 3.0-beta, a pending <tt>receive()</tt> |
398 | or <tt>send()</tt> call is currently not awakened, and may be a reason for a non-detected cancel. | 491 | or <tt>send()</tt> call is awakened. This means the execution of the lane will resume although the operation has |
492 | not completed, to give the lane a chance to detect cancellation. The code should be able to handle this situation appropriately if required. | ||
399 | It is also possible to manually test for cancel requests with <tt>cancel_test()</tt>. | 493 | It is also possible to manually test for cancel requests with <tt>cancel_test()</tt>. |
400 | </p> | 494 | </p> |
401 | 495 | ||
@@ -470,7 +564,7 @@ level locking is required; each Linda operation is atomic. | |||
470 | <p>Characteristics of the Lanes implementation of Lindas are: | 564 | <p>Characteristics of the Lanes implementation of Lindas are: |
471 | 565 | ||
472 | <ul> | 566 | <ul> |
473 | <li>keys can be of number, string or boolean type | 567 | <li>keys can be of boolean, number, string or light userdata type |
474 | </li> | 568 | </li> |
475 | <li>values can be any type supported by inter-state copying (same limits | 569 | <li>values can be any type supported by inter-state copying (same limits |
476 | as for function parameters and upvalues) | 570 | as for function parameters and upvalues) |
@@ -548,6 +642,23 @@ Writing to a slot overwrites existing value, and clears any possible queued | |||
548 | entries. Table access and <tt>send</tt>/<tt>receive</tt> can be used together; | 642 | entries. Table access and <tt>send</tt>/<tt>receive</tt> can be used together; |
549 | reading a slot essentially peeks the next outcoming value of a queue. | 643 | reading a slot essentially peeks the next outcoming value of a queue. |
550 | </p> | 644 | </p> |
645 | <p> | ||
646 | |||
647 | <table border="1" bgcolor="#E0E0FF" cellpadding="10"> | ||
648 | <tr> | ||
649 | <td> | ||
650 | <code>[val]= linda_h:count( [key[,...]])</code> | ||
651 | </table> | ||
652 | |||
653 | </p> | ||
654 | <p> | ||
655 | Returns some information about the contents of the linda. | ||
656 | <br/>If no key is specified, and the linda is empty, returns nothing. | ||
657 | <br/>If no key is specified, and the linda is not empty, returns a table of key/count pairs that counts the number of items in each | ||
658 | of the exiting keys of the linda. This count can be 0 if the key has been used but is empty. | ||
659 | <br/>If a single key is specified, returns the number of pending items, or nothing if the key is unknown. | ||
660 | <br/>If more than one key is specified, return a table of key/count pairs for the known keys. | ||
661 | </p> | ||
551 | 662 | ||
552 | <!-- | 663 | <!-- |
553 | <p> | 664 | <p> |
@@ -589,6 +700,8 @@ you want to use several? | |||
589 | <li>Performance. Changing any slot in a Linda causes all pending threads | 700 | <li>Performance. Changing any slot in a Linda causes all pending threads |
590 | for that Linda to be momentarily awakened (at least in the C level). | 701 | for that Linda to be momentarily awakened (at least in the C level). |
591 | This can degrade performance due to unnecessary OS level context switches. | 702 | This can degrade performance due to unnecessary OS level context switches. |
703 | The more keeper states you declared with <tt>lanes.configure()</tt> the less | ||
704 | this should be a problem. | ||
592 | </li> | 705 | </li> |
593 | </ul> | 706 | </ul> |
594 | 707 | ||
@@ -610,6 +723,10 @@ events to a common Linda, but... :).</font> | |||
610 | </table> | 723 | </table> |
611 | 724 | ||
612 | <p> | 725 | <p> |
726 | Timers are implemented as a lane. They can be disabled by passing <tt>"NO_TIMERS"</tt> | ||
727 | to <tt>lanes.configure()</tt>. | ||
728 | </p> | ||
729 | <p> | ||
613 | Timers can be run once, or in a reoccurring fashion (<tt>period_secs > 0</tt>). | 730 | Timers can be run once, or in a reoccurring fashion (<tt>period_secs > 0</tt>). |
614 | The first occurrence can be given either as a date or as a relative delay in seconds. | 731 | The first occurrence can be given either as a date or as a relative delay in seconds. |
615 | The <tt>date</tt> table is like what <tt>os.date("*t")</tt> returns, in the | 732 | The <tt>date</tt> table is like what <tt>os.date("*t")</tt> returns, in the |
@@ -625,7 +742,8 @@ A timer can be stopped simply by <tt>first_secs=0</tt> and no period. | |||
625 | 742 | ||
626 | <table border=1 bgcolor="#FFFFE0" width=500><tr><td> | 743 | <table border=1 bgcolor="#FFFFE0" width=500><tr><td> |
627 | <pre> | 744 | <pre> |
628 | require "lanes" | 745 | local lanes = require "lanes" |
746 | lanes.configure( 1) | ||
629 | 747 | ||
630 | local linda= lanes.linda() | 748 | local linda= lanes.linda() |
631 | 749 | ||
@@ -960,9 +1078,49 @@ its actual value. | |||
960 | <h2 id="changes">Change log</h2> | 1078 | <h2 id="changes">Change log</h2> |
961 | 1079 | ||
962 | <p> | 1080 | <p> |
1081 | Feb-2012 | ||
1082 | <ul> | ||
1083 | <li>Added support for an on_state_create callback invoked on a pristine Lua state created by Lanes.</li> | ||
1084 | <li>This required a change in the <tt>lanes.configure()</tt> signature, hence the minor version bump.</li> | ||
1085 | </ul> | ||
963 | 1086 | ||
964 | Mar-2011 (2.1.0) | 1087 | |
965 | <ul> | 1088 | Nov-2011 |
1089 | <ul> | ||
1090 | <li>process exit change: close everything at GC when main state closes, not when atexit() handlers are processed</li> | ||
1091 | <li>Lua 5.2-style module:</li> | ||
1092 | <ul> | ||
1093 | <li>module() is no longer used to implement lanes.lua</li> | ||
1094 | <li>a global "lanes" variable is no longer created when the module is required</li> | ||
1095 | <li>the Lanes module table is returned instead</li> | ||
1096 | </ul> | ||
1097 | <li>Lanes must be initialized before used:</li> | ||
1098 | <ul> | ||
1099 | <li>the first occurence of 'require "lanes"' produces a minimal interface that only contains a configure() function</li> | ||
1100 | <li>the remainder of the interface is made available once this function is called</li> | ||
1101 | <li>subsequent calls to configure() do nothing</li> | ||
1102 | <li>configure() controls the number of keeper states and the startup of timers</li> | ||
1103 | </ul> | ||
1104 | <li>* LuaJIT 2 compatibility</li> | ||
1105 | <ul> | ||
1106 | <li>non-Lua functions are no longer copied by creating a C closure from a C pointer, but through 2-way lookup tables</li> | ||
1107 | <li>this means that if a lane function body pulls non-Lua functions, the lane generator description must contain the list of libraries and modules that exports them</li> | ||
1108 | <li>introduces a change in configuration .globals management: contents are copied *after* std libs are loaded</li> | ||
1109 | <li>new .required configuration entry to list modules that must be require()'ed before lane body is transferred</li> | ||
1110 | </ul> | ||
1111 | <li>lane:cancel() wakes up waiting lindas like what is done at lane shutdown</li> | ||
1112 | <li>removed packagepath and packagecpath options, replaced by a package table, whose fields path, cpath, loaders, preload are transfered</li> | ||
1113 | </ul> | ||
1114 | |||
1115 | Mar-2011 (not yet versioned) | ||
1116 | <ul> | ||
1117 | <li>linda honors __tostring and __concat</li> | ||
1118 | <li>new accessor linda:count(), to get info about data stored inside a linda.</li> | ||
1119 | <li>new lanes options packagepath and packagecpath, in case one needs to set them differently than the default.</li> | ||
1120 | </ul> | ||
1121 | |||
1122 | Mar-2011 (2.1.0) | ||
1123 | <ul> | ||
966 | <li>fixed potential crash at application shutdown when calling lua_close() on a killed thread's VM.</li> | 1124 | <li>fixed potential crash at application shutdown when calling lua_close() on a killed thread's VM.</li> |
967 | <li>exposed cancel_test() in the lanes to enable manual testing for cancellation requests.</li> | 1125 | <li>exposed cancel_test() in the lanes to enable manual testing for cancellation requests.</li> |
968 | <li>removed kludgy {globals={threadName}} support, replaced with a new function set_debug_threadname().</li> | 1126 | <li>removed kludgy {globals={threadName}} support, replaced with a new function set_debug_threadname().</li> |