aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2011-02-12 17:06:03 +0100
committerBenoit Germain <bnt.germain@gmail.com>2011-02-12 17:06:03 +0100
commita661736f7984292a41d71847de68590f6b8ca08a (patch)
tree43e0799c20e835f1cc2d8c5fa1324b64301763e0 /docs
parentc91a03bd956bf19848253bded8217687ccd2ad81 (diff)
downloadlanes-a661736f7984292a41d71847de68590f6b8ca08a.tar.gz
lanes-a661736f7984292a41d71847de68590f6b8ca08a.tar.bz2
lanes-a661736f7984292a41d71847de68590f6b8ca08a.zip
Changed idfunc signature and contract to clarify that fact it is not lua-callable and to be able to require the module it was exported from in the target lanes.
Diffstat (limited to 'docs')
-rw-r--r--docs/index.html99
1 files changed, 53 insertions, 46 deletions
diff --git a/docs/index.html b/docs/index.html
index fec2212..9d66510 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -21,11 +21,11 @@
21 <tr> 21 <tr>
22 <td align="center"> 22 <td align="center">
23 <a href="http://www.lua.org"> 23 <a href="http://www.lua.org">
24 <img src="http://akauppi.googlepages.com/multi.png" alt="Lua" align="middle" border="0" height="120" width="128" /> 24 <img src="multi.png" alt="Lua" align="middle" border="0" height="120" width="128" />
25 <img src="http://akauppi.googlepages.com/multi.png" alt="Lua" align="middle" border="0" height="120" width="128" /> 25 <img src="multi.png" alt="Lua" align="middle" border="0" height="120" width="128" />
26 <img src="http://akauppi.googlepages.com/multi.png" alt="Lua" align="middle" border="0" height="120" width="128" /> 26 <img src="multi.png" alt="Lua" align="middle" border="0" height="120" width="128" />
27 <img src="http://akauppi.googlepages.com/multi.png" alt="Lua" align="middle" border="0" height="120" width="128" /> 27 <img src="multi.png" alt="Lua" align="middle" border="0" height="120" width="128" />
28 <img src="http://akauppi.googlepages.com/multi.png" alt="Lua" align="middle" border="0" height="120" width="128" /> 28 <img src="multi.png" alt="Lua" align="middle" border="0" height="120" width="128" />
29 </a></td> 29 </a></td>
30 </tr> 30 </tr>
31 <tr> 31 <tr>
@@ -56,7 +56,7 @@
56 56
57<p><br/><font size="-1"><i>Copyright &copy; 2007-11 Asko Kauppi. All rights reserved.</i> 57<p><br/><font size="-1"><i>Copyright &copy; 2007-11 Asko Kauppi. 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 3-Jan-11, and applies to version 2.0.10. 59 </p><p>This document was revised on 12-Feb-11, and applies to version 2.0.11.
60</font></p> 60</font></p>
61 61
62</center> 62</center>
@@ -124,15 +124,14 @@
124 <li>Windows 2000/XP and later <font size="-1">(MinGW or Visual C++ 2005/2008)</font></li> 124 <li>Windows 2000/XP and later <font size="-1">(MinGW or Visual C++ 2005/2008)</font></li>
125<!-- 125<!--
126 Other OS'es here once people help test them. (and the tester's name) 126 Other OS'es here once people help test them. (and the tester's name)
127 127
128 Win64, BSD, Linux x64, Linux embedded, QNX, Solaris, ... 128 Win64, BSD, Linux x64, Linux embedded, QNX, Solaris, ...
129--> 129-->
130 </ul> 130 </ul>
131 131
132 <p>The underlying threading code can be compiled either towards Win32 API 132 <p>The underlying threading code can be compiled either towards Win32 API
133 or <a TARGET="_blank" HREF="http://en.wikipedia.org/wiki/POSIX_Threads">Pthreads</a>. Unfortunately, thread prioritation under Pthreads is a JOKE, 133 or <a TARGET="_blank" HREF="http://en.wikipedia.org/wiki/POSIX_Threads">Pthreads</a>. Unfortunately, thread prioritization under Pthreads is a JOKE,
134 requiring OS specific tweaks and guessing undocumented behaviour. Other 134 requiring OS specific tweaks and guessing undocumented behaviour. Other features should be portable to any modern platform.
135 features should be portable to any modern platform.
136 </p> 135 </p>
137</p> 136</p>
138 137
@@ -147,7 +146,7 @@ details and limitations.
147</p> 146</p>
148 147
149<p>To install Lanes, all you need are the <tt>lanes.lua</tt> and <tt>lua51-lanes.so|dll</tt> 148<p>To install Lanes, all you need are the <tt>lanes.lua</tt> and <tt>lua51-lanes.so|dll</tt>
150files to be reachable by Lua (see LUA_PATH, LUA_CPATH). 149files to be reachable by Lua (see LUA_PATH, LUA_CPATH).
151 150
152Or use <A HREF="http://www.luarocks.org" TARGET="_blank">Lua Rocks</A> package management. 151Or use <A HREF="http://www.luarocks.org" TARGET="_blank">Lua Rocks</A> package management.
153</p> 152</p>
@@ -264,7 +263,7 @@ also in the new lanes.
264 by platform. Especially Linux kernel 2.6 is not supporting priorities in user mode. 263 by platform. Especially Linux kernel 2.6 is not supporting priorities in user mode.
265 </td></tr> 264 </td></tr>
266 </table> 265 </table>
267 266
268</p> 267</p>
269 268
270<h3>Free running lanes</h3> 269<h3>Free running lanes</h3>
@@ -383,7 +382,7 @@ for the request to be processed, or a timeout to occur.
383Returns <tt>true</tt> if the lane was already done (in <tt>"done"</tt>, <tt>"error"</tt> or <tt>"cancelled"</tt> status) 382Returns <tt>true</tt> if the lane was already done (in <tt>"done"</tt>, <tt>"error"</tt> or <tt>"cancelled"</tt> status)
384or if the cancellation was fruitful within timeout period. 383or if the cancellation was fruitful within timeout period.
385</p><p> 384</p><p>
386If the lane is still running and <tt>force_kill</tt> is <tt>true</tt>, the 385If the lane is still running and <tt>force_kill</tt> is <tt>true</tt>, the
387OS thread running the lane is forcefully killed. This means no GC, and should 386OS thread running the lane is forcefully killed. This means no GC, and should
388generally be the last resort. 387generally be the last resort.
389</p> 388</p>
@@ -404,16 +403,16 @@ or <tt>send</tt> call is currently not awakened, and may be a reason for a non-d
404</table> 403</table>
405 404
406<p>The <tt>error</tt> call is used for throwing exceptions in Lua. What Lua 405<p>The <tt>error</tt> call is used for throwing exceptions in Lua. What Lua
407does not offer, however, is scoped <a href="http://en.wikipedia.org/wiki/Finalizer">finalizers</a> 406does not offer, however, is scoped <a href="http://en.wikipedia.org/wiki/Finalizer">finalizers</a>
408that would get called when a certain block of instructions gets exited, whether 407that would get called when a certain block of instructions gets exited, whether
409through peaceful return or abrupt <tt>error</tt>. 408through peaceful return or abrupt <tt>error</tt>.
410</p> 409</p>
411<p>Since 2.0.3, Lanes prepares a function <tt>set_finalizer</tt> for doing this. 410<p>Since 2.0.3, Lanes prepares a function <tt>set_finalizer</tt> for doing this.
412Any functions given to it will be called in the lane Lua state, just prior to 411Any functions given to it will be called in the lane Lua state, just prior to
413closing it. They are not called in any particular order. 412closing it. They are not called in any particular order.
414</p> 413</p>
415<p>An error in a finalizer itself overrides the state of the regular chunk 414<p>An error in a finalizer itself overrides the state of the regular chunk
416(in practise, it would be highly preferable <i>not</i> to have errors in finalizers). 415(in practise, it would be highly preferable <i>not</i> to have errors in finalizers).
417If one finalizer errors, the others may not get called. 416If one finalizer errors, the others may not get called.
418</p> 417</p>
419 418
@@ -424,7 +423,7 @@ If one finalizer errors, the others may not get called.
424 423
425<p>Communications between lanes is completely detached from the lane handles 424<p>Communications between lanes is completely detached from the lane handles
426themselves. By itself, a lane can only provide return values once it's finished, 425themselves. By itself, a lane can only provide return values once it's finished,
427or throw an error. Needs to communicate during runtime are handled by <A HREF="http://en.wikipedia.org/wiki/Linda_%28coordination_language%29" TARGET="_blank">Linda objects</A>, which are 426or throw an error. Needs to communicate during runtime are handled by <A HREF="http://en.wikipedia.org/wiki/Linda_%28coordination_language%29" TARGET="_blank">Linda objects</A>, which are
428<A HREF="#deep_userdata">deep userdata</A> instances. They can be provided to a lane 427<A HREF="#deep_userdata">deep userdata</A> instances. They can be provided to a lane
429as startup parameters, upvalues or in some other Linda's message. 428as startup parameters, upvalues or in some other Linda's message.
430</p><p> 429</p><p>
@@ -445,7 +444,7 @@ level locking is required; each Linda operation is atomic.
445 linda:send( "x", i ) -- linda as upvalue 444 linda:send( "x", i ) -- linda as upvalue
446 end 445 end
447 end 446 end
448 447
449 a= lanes.gen("",loop)( 10000 ) 448 a= lanes.gen("",loop)( 10000 )
450 449
451 while true do 450 while true do
@@ -512,7 +511,7 @@ many producers, and many consumers. It's up to you.
512if the queue limit was met, and the queue did not empty enough during the given 511if the queue limit was met, and the queue did not empty enough during the given
513timeout. 512timeout.
514</p><p> 513</p><p>
515Equally, <tt>receive</tt> returns a value and the key that provided the value, 514Equally, <tt>receive</tt> returns a value and the key that provided the value,
516or nothing for timeout. Note that <tt>nil</tt>s can be sent and received; 515or nothing for timeout. Note that <tt>nil</tt>s can be sent and received;
517the <tt>key</tt> value will tell it apart from a timeout. 516the <tt>key</tt> value will tell it apart from a timeout.
518</p><p> 517</p><p>
@@ -537,8 +536,8 @@ be used for making priority queues.
537The table access methods are for accessing a slot without queuing or consuming. 536The table access methods are for accessing a slot without queuing or consuming.
538They can be used for making shared tables of storage among the lanes. 537They can be used for making shared tables of storage among the lanes.
539</p><p> 538</p><p>
540Writing to a slot overwrites existing value, and clears any possible queued 539Writing to a slot overwrites existing value, and clears any possible queued
541entries. Table access and <tt>send</tt>/<tt>receive</tt> can be used together; 540entries. Table access and <tt>send</tt>/<tt>receive</tt> can be used together;
542reading a slot essentially peeks the next outcoming value of a queue. 541reading a slot essentially peeks the next outcoming value of a queue.
543</p> 542</p>
544 543
@@ -554,7 +553,7 @@ discussing it is good for a preview of how deep userdata works.
554Because proxy objects (<tt>linda_h</tt>) are just pointers to the real, deep 553Because proxy objects (<tt>linda_h</tt>) are just pointers to the real, deep
555userdata, they cannot be used to identify a certain Linda from the others. 554userdata, they cannot be used to identify a certain Linda from the others.
556The internal timer system needs to do this, and the <tt>:deep()</tt> method 555The internal timer system needs to do this, and the <tt>:deep()</tt> method
557has been added for its use. It returns a light userdata pointing to the 556has been added for its use. It returns a light userdata pointing to the
558<i>actual</i> deep object, and thus can be used for seeing, which proxies actually 557<i>actual</i> deep object, and thus can be used for seeing, which proxies actually
559mean the same underlying object. You might or might not need a similar system 558mean the same underlying object. You might or might not need a similar system
560with your own deep userdata. 559with your own deep userdata.
@@ -574,13 +573,13 @@ you want to use several?
574 for the other. This keeps your code clear and readable. You can pass 573 for the other. This keeps your code clear and readable. You can pass
575 multiple Linda handles to a lane with practically no added cost. 574 multiple Linda handles to a lane with practically no added cost.
576 </li> 575 </li>
577 576
578 <li>Namespace control. Linda keys have a "flat" namespace, so collisions 577 <li>Namespace control. Linda keys have a "flat" namespace, so collisions
579 are possible if you try to use the same Linda for too many separate uses. 578 are possible if you try to use the same Linda for too many separate uses.
580 </li> 579 </li>
581 580
582 <li>Performance. Changing any slot in a Linda causes all pending threads 581 <li>Performance. Changing any slot in a Linda causes all pending threads
583 for that Linda to be momentarily awakened (at least in the C level). 582 for that Linda to be momentarily awakened (at least in the C level).
584 This can degrade performance due to unnecessary OS level context switches. 583 This can degrade performance due to unnecessary OS level context switches.
585 </li> 584 </li>
586</ul> 585</ul>
@@ -603,13 +602,13 @@ events to a common Linda, but... :).</font>
603</table> 602</table>
604 603
605<p> 604<p>
606Timers can be run once, or in a reoccurring fashion (<tt>period_secs > 0</tt>). 605Timers can be run once, or in a reoccurring fashion (<tt>period_secs > 0</tt>).
607The first occurrence can be given either as a date or as a relative delay in seconds. 606The first occurrence can be given either as a date or as a relative delay in seconds.
608The <tt>date</tt> table is like what <tt>os.date("*t")</tt> returns, in the 607The <tt>date</tt> table is like what <tt>os.date("*t")</tt> returns, in the
609local time zone. 608local time zone.
610</p><p> 609</p><p>
611Once a timer expires, the <tt>key</tt> is set with the current time 610Once a timer expires, the <tt>key</tt> is set with the current time
612(in seconds, same offset as <tt>os.time()</tt> but with millisecond accuracy). 611(in seconds, same offset as <tt>os.time()</tt> but with millisecond accuracy).
613The key can be waited upon using the regular Linda <tt>:receive()</tt> 612The key can be waited upon using the regular Linda <tt>:receive()</tt>
614method. 613method.
615</p><p> 614</p><p>
@@ -632,17 +631,17 @@ A timer can be stopped simply by <tt>first_secs=0</tt> and no period.
632 t.sec= 0 631 t.sec= 0
633 632
634 lanes.timer( linda, "min", t, 60 ) -- reoccur every minute (sharp) 633 lanes.timer( linda, "min", t, 60 ) -- reoccur every minute (sharp)
635 634
636 while true do 635 while true do
637 local v,key= linda:receive( "sec", "min" ) 636 local v,key= linda:receive( "sec", "min" )
638 print( "Timer "..key..": "..v ) 637 print( "Timer "..key..": "..v )
639 end 638 end
640</pre> 639</pre>
641</table> 640</table>
642 641
643</p><p> 642</p><p>
644NOTE: Timer keys are set, not queued, so missing a beat is possible especially 643NOTE: Timer keys are set, not queued, so missing a beat is possible especially
645if the timer cycle is extremely small. The key value can be used to know the 644if the timer cycle is extremely small. The key value can be used to know the
646actual time passed. 645actual time passed.
647</p><p> 646</p><p>
648<table> 647<table>
@@ -704,7 +703,7 @@ Similar sugar exists for atomic counters:
704</table> 703</table>
705</p><p> 704</p><p>
706 705
707Each time called, the generated function will change <tt>linda[key]</tt> 706Each time called, the generated function will change <tt>linda[key]</tt>
708atomically, without other lanes being able to interfere. The new value is 707atomically, without other lanes being able to interfere. The new value is
709returned. You can use either <tt>diff 0.0</tt> or <tt>get</tt> to just read the current 708returned. You can use either <tt>diff 0.0</tt> or <tt>get</tt> to just read the current
710value. 709value.
@@ -725,7 +724,7 @@ Note that the generated functions can be passed on to other lanes.
725<p><ul> 724<p><ul>
726 <li>Booleans, numbers, strings, light userdata, Lua functions and tables of such can always be passed. 725 <li>Booleans, numbers, strings, light userdata, Lua functions and tables of such can always be passed.
727 </li> 726 </li>
728 <li>Cyclic tables and/or duplicate references are allowed and reproduced appropriately, 727 <li>Cyclic tables and/or duplicate references are allowed and reproduced appropriately,
729 but only <u>within the same transmission</u>. 728 but only <u>within the same transmission</u>.
730 <ul> 729 <ul>
731 <li>using the same source table in multiple Linda messages keeps no ties between the tables 730 <li>using the same source table in multiple Linda messages keeps no ties between the tables
@@ -777,14 +776,14 @@ should be covered into a one-time-only construct such as below.
777 int luaopen_module( lua_State *L ) 776 int luaopen_module( lua_State *L )
778 { 777 {
779 static char been_here; /* 0 by ANSI C */ 778 static char been_here; /* 0 by ANSI C */
780 779
781 /* Calls to 'require' serialized by Lanes; this is safe.&nbsp;&nbsp; 780 /* Calls to 'require' serialized by Lanes; this is safe.&nbsp;&nbsp;
782 */ 781 */
783 if (!been_here) { 782 if (!been_here) {
784 been_here= 1; 783 been_here= 1;
785 ... one time initializations ... 784 ... one time initializations ...
786 } 785 }
787 786
788 ... binding to Lua ... 787 ... binding to Lua ...
789 } 788 }
790</pre> 789</pre>
@@ -804,8 +803,9 @@ used for creation and deletion of your deep userdata (the shared resource),
804and for making metatables for the state-specific proxies for accessing it. 803and for making metatables for the state-specific proxies for accessing it.
805Take a look at <tt>linda_id</tt> in <tt>lanes.c</tt>. 804Take a look at <tt>linda_id</tt> in <tt>lanes.c</tt>.
806 </li> 805 </li>
807 <li>Create your userdata using <tt>luaG_deep_userdata()</tt>, which is 806 <li>Instanciate your userdata using <tt>luaG_deep_userdata()</tt>,
808 a Lua-callable function. Given an <tt>idfunc</tt>, it sets up the support 807 instead of the regular <tt>lua_newuserdata()</tt>.
808 Given an <tt>idfunc</tt>, it sets up the support
809 structures and returns a state-specific proxy userdata for accessing your 809 structures and returns a state-specific proxy userdata for accessing your
810 data. This proxy can also be copied over to other lanes. 810 data. This proxy can also be copied over to other lanes.
811 </li> 811 </li>
@@ -815,7 +815,7 @@ Take a look at <tt>linda_id</tt> in <tt>lanes.c</tt>.
815</ol> 815</ol>
816 816
817<p>Deep userdata management will take care of tying to <tt>__gc</tt> methods, 817<p>Deep userdata management will take care of tying to <tt>__gc</tt> methods,
818and doing reference counting to see how many proxies are still there for 818and doing reference counting to see how many proxies are still there for
819accessing the data. Once there are none, the data will be freed through a call 819accessing the data. Once there are none, the data will be freed through a call
820to the <tt>idfunc</tt> you provided. 820to the <tt>idfunc</tt> you provided.
821</p> 821</p>
@@ -850,7 +850,7 @@ something like this:
850<pre> 850<pre>
851 A: print( 1, 2, 3, 4 ) 851 A: print( 1, 2, 3, 4 )
852 B: print( 'a', 'b', 'c', 'd' ) 852 B: print( 'a', 'b', 'c', 'd' )
853 853
854 1 a b 2 3 c d 4 854 1 a b 2 3 c d 4
855</pre> 855</pre>
856 856
@@ -870,7 +870,7 @@ Here are some things one should consider, if best performance is vital:
870<ul> 870<ul>
871 <li>Data passing (parameters, upvalues, Linda messages) is generally fast, 871 <li>Data passing (parameters, upvalues, Linda messages) is generally fast,
872 doing two binary state-to-state copies (from source state to hidden state, 872 doing two binary state-to-state copies (from source state to hidden state,
873 hidden state to target state). Remember that not only the function you 873 hidden state to target state). Remember that not only the function you
874 specify but also its upvalues, their upvalues, etc. etc. will get copied. 874 specify but also its upvalues, their upvalues, etc. etc. will get copied.
875 </li> 875 </li>
876 <li>Lane startup is fast (1000's of lanes a second), depending on the 876 <li>Lane startup is fast (1000's of lanes a second), depending on the
@@ -894,7 +894,7 @@ Here are some things one should consider, if best performance is vital:
894 merged into one main timer state (see <tt>timer.lua</tt>); no OS side 894 merged into one main timer state (see <tt>timer.lua</tt>); no OS side
895 timers are utilized. 895 timers are utilized.
896 </li> 896 </li>
897 <li>Lindas are hashed to a fixed number of "keeper states", which are a locking entity. 897 <li>Lindas are hashed to a fixed number of "keeper states", which are a locking entity.
898 If you are using a lot of Linda objects, 898 If you are using a lot of Linda objects,
899 it may be useful to try having more of these keeper states. By default, 899 it may be useful to try having more of these keeper states. By default,
900 only one is used (see <tt>KEEPER_STATES_N</tt>), but this is an implementation detail. 900 only one is used (see <tt>KEEPER_STATES_N</tt>), but this is an implementation detail.
@@ -907,7 +907,7 @@ Here are some things one should consider, if best performance is vital:
907 907
908<p> 908<p>
909Cancellation of lanes uses the Lua error mechanism with a special lightuserdata 909Cancellation of lanes uses the Lua error mechanism with a special lightuserdata
910error sentinel. 910error sentinel.
911If you use <tt>pcall</tt> in code that needs to be cancellable 911If you use <tt>pcall</tt> in code that needs to be cancellable
912from the outside, the special error might not get through to Lanes, thus 912from the outside, the special error might not get through to Lanes, thus
913preventing the Lane from being cleanly cancelled. You should throw any 913preventing the Lane from being cleanly cancelled. You should throw any
@@ -929,6 +929,13 @@ its actual value.
929<h2 id="changes">Change log</h2> 929<h2 id="changes">Change log</h2>
930 930
931<p> 931<p>
932Feb-2011 (2.0.11):
933<ul>
934 <li>Fixed bug where reference to Linda object was dropped for a short time (crashing if GC was run during that time).</li>
935 <li>Changed the atexit code to trip the timer thread's write signal.</li>
936 <li>Changed lanes.c to export functions as a module rather than writing them directly to the globals table.</li>
937</ul>
938
932Jan-2011 (2.0.10): 939Jan-2011 (2.0.10):
933<ul> 940<ul>
934 <li>linda_send was waiting on the wrong signal</li> 941 <li>linda_send was waiting on the wrong signal</li>