diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2013-10-03 11:29:15 +0200 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2013-10-03 11:29:15 +0200 |
commit | 69c42e1908f293498733eb5fa433f8742a513deb (patch) | |
tree | 02b23b118a976fc8668896ed60db3050e8c688a9 | |
parent | 24f7fb84e3fc1bd5ee42111957c843d59e143d10 (diff) | |
download | lanes-69c42e1908f293498733eb5fa433f8742a513deb.tar.gz lanes-69c42e1908f293498733eb5fa433f8742a513deb.tar.bz2 lanes-69c42e1908f293498733eb5fa433f8742a513deb.zip |
Update fibonacci.lua
Fix issue #61.
Pulling lanes as an upvalue is not a good idea after all, due to the fact that lanes.core changes its public API when lanes.core.configure() is called.
-rw-r--r-- | tests/fibonacci.lua | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/tests/fibonacci.lua b/tests/fibonacci.lua index a5e0b2a..5cdb4be 100644 --- a/tests/fibonacci.lua +++ b/tests/fibonacci.lua | |||
@@ -24,11 +24,16 @@ end | |||
24 | -- | 24 | -- |
25 | local KNOWN= { [0]=0, 1,1,2,3,5,8,13,21,34,55,89,144 } | 25 | local KNOWN= { [0]=0, 1,1,2,3,5,8,13,21,34,55,89,144 } |
26 | 26 | ||
27 | -- | 27 | -- dummy function so that we don't error when fib() is launched from the master state |
28 | set_debug_threadname = function ( ...) | ||
29 | end | ||
30 | |||
31 | -- | ||
28 | -- uint= fib( n_uint ) | 32 | -- uint= fib( n_uint ) |
29 | -- | 33 | -- |
30 | local function fib( n ) | 34 | local function fib( n ) |
31 | --local lanes = require"lanes".configure() | 35 | set_debug_threadname( "fib(" .. n .. ")") |
36 | local lanes = require"lanes".configure() | ||
32 | -- | 37 | -- |
33 | local sum | 38 | local sum |
34 | local floor= assert(math.floor) | 39 | local floor= assert(math.floor) |
@@ -40,11 +45,7 @@ local function fib( n ) | |||
40 | else | 45 | else |
41 | -- Splits into two; this task remains waiting for the results | 46 | -- Splits into two; this task remains waiting for the results |
42 | -- | 47 | -- |
43 | -- note that lanes is pulled in by upvalue, so we need lanes.core to be available | 48 | local gen_f= lanes.gen( "*", fib) |
44 | -- the other solution is to require "lanes" from inside the lane body, as in: | ||
45 | -- local lanes = require"lanes".configure() | ||
46 | -- local gen_f= lanes.gen( "*", fib) | ||
47 | local gen_f= lanes.gen( "*", {required={"lanes.core"}}, fib) | ||
48 | 49 | ||
49 | local n1=floor(n/2) +1 | 50 | local n1=floor(n/2) +1 |
50 | local n2=floor(n/2) -1 + n%2 | 51 | local n2=floor(n/2) -1 + n%2 |
@@ -93,4 +94,3 @@ local N= 80 | |||
93 | local res= fib(N) | 94 | local res= fib(N) |
94 | print( right[N], res ) | 95 | print( right[N], res ) |
95 | -- assert( res==right[N] ) -- can't guarantee such a large number will match exactly | 96 | -- assert( res==right[N] ) -- can't guarantee such a large number will match exactly |
96 | |||