diff options
Diffstat (limited to 'tests/deadlock.lua')
-rw-r--r-- | tests/deadlock.lua | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/tests/deadlock.lua b/tests/deadlock.lua index c38ca13..bbbda8d 100644 --- a/tests/deadlock.lua +++ b/tests/deadlock.lua | |||
@@ -1,8 +1,10 @@ | |||
1 | -- this script tests the fix of a bug that could cause the mutex of a keeper state to remain locked | 1 | -- this script tests the fix of a bug that could cause the mutex of a keeper state to remain locked |
2 | -- see https://github.com/LuaLanes/lanes/commit/0cc1c9c9dcea5955f7dab921d9a2fff78c4e1729 | 2 | -- see https://github.com/LuaLanes/lanes/commit/0cc1c9c9dcea5955f7dab921d9a2fff78c4e1729 |
3 | 3 | ||
4 | local lanes = require('lanes').configure{with_timers=false} | 4 | local lanes = require "lanes" |
5 | local linda = lanes.linda "deadlock_linda" | 5 | |
6 | -- Lua 5.1 compatibility | ||
7 | local table_unpack = table.unpack or unpack | ||
6 | 8 | ||
7 | local SLEEP = function(...) | 9 | local SLEEP = function(...) |
8 | local k, v = lanes.sleep(...) | 10 | local k, v = lanes.sleep(...) |
@@ -14,27 +16,28 @@ print "let's begin" | |||
14 | local do_extra_stuff = true | 16 | local do_extra_stuff = true |
15 | 17 | ||
16 | if do_extra_stuff then | 18 | if do_extra_stuff then |
17 | -- just something to make send() succeed and receive() fail (any C function exposed by some module will do) | 19 | local linda = lanes.linda "deadlock_linda" |
18 | local payload = { lanes.require('socket').connect } | 20 | -- just something to make send() succeed and receive() fail |
19 | 21 | local payload = { io.flush } | |
20 | -- lane generator | 22 | |
21 | local g = lanes.gen('*', function() | 23 | -- lane generator. don't initialize "io" base library so that it is not known in the lane |
22 | set_debug_threadname( "deadlock_lane") | 24 | local g = lanes.gen('base,table', function() |
23 | -- wrapping inside pcall makes the Lanes module unaware that something went wrong | 25 | set_debug_threadname( "deadlock_lane") |
24 | print( "In lane 1:", table.unpack{ pcall( linda.receive, linda, 'tmp')}) | 26 | -- wrapping inside pcall makes the Lanes module unaware that something went wrong |
25 | -- with the bug not fixed, and non-recursive mutexes, we can hang here | 27 | print( "In lane 1:", table_unpack{ pcall( linda.receive, linda, 'tmp')}) |
26 | print( "In lane 2:", table.unpack{ pcall( linda.receive, linda, 'tmp')}) | 28 | -- with the bug not fixed, and non-recursive mutexes, we can hang here |
27 | -- return something out of the lane | 29 | print( "In lane 2:", table_unpack{ pcall( linda.receive, linda, 'tmp')}) |
28 | return 33, 55 | 30 | -- return something out of the lane |
29 | end) | 31 | return 33, 55 |
30 | 32 | end) | |
31 | -- send payload twice. succeeds because sending stores a function identification string in the linda's keeper state | 33 | |
32 | linda:send( 'tmp', payload, payload) | 34 | -- send payload twice. succeeds because sending stores a function identification string in the linda's keeper state |
33 | -- start the lane | 35 | linda:send( 'tmp', payload, payload) |
34 | local h = g() | 36 | -- start the lane |
35 | -- wait for lane completion | 37 | local h = g() |
36 | local err, stack = h:join() | 38 | -- wait for lane completion |
37 | print( 'result of lane execution', err, stack) | 39 | local err, stack = h:join() |
40 | print( 'result of lane execution', err, stack) | ||
38 | end | 41 | end |
39 | 42 | ||
40 | -- With the bug not fixed, the linda keeper's mutex is still acquired, | 43 | -- With the bug not fixed, the linda keeper's mutex is still acquired, |