diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2018-11-08 17:32:05 +0100 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2018-11-08 17:32:05 +0100 |
commit | 0cc1c9c9dcea5955f7dab921d9a2fff78c4e1729 (patch) | |
tree | 5c35acf11087f9b60b24599695f1d3c348ebaa25 /tests | |
parent | a142eb1e1ee81919d10b55bb7fa2e33636098d85 (diff) | |
download | lanes-0cc1c9c9dcea5955f7dab921d9a2fff78c4e1729.tar.gz lanes-0cc1c9c9dcea5955f7dab921d9a2fff78c4e1729.tar.bz2 lanes-0cc1c9c9dcea5955f7dab921d9a2fff78c4e1729.zip |
Make sure any linda operation that can raise an error won't ever leave a mutex unreleased
Diffstat (limited to 'tests')
-rw-r--r-- | tests/deadlock.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/deadlock.lua b/tests/deadlock.lua new file mode 100644 index 0000000..8ccae89 --- /dev/null +++ b/tests/deadlock.lua | |||
@@ -0,0 +1,28 @@ | |||
1 | local lanes = require('lanes').configure() | ||
2 | local linda = lanes.linda "deadlock_linda" | ||
3 | |||
4 | local do_extra_stuff = true | ||
5 | |||
6 | if do_extra_stuff then | ||
7 | -- just something to make send() succeed and receive() fail: | ||
8 | local payload = { lanes.require('socket').connect } | ||
9 | |||
10 | -- lane generator | ||
11 | local g = lanes.gen('*', function() | ||
12 | set_debug_threadname "deadlock_lane" | ||
13 | print("In lane 1:", table.unpack{pcall(linda.receive, linda, 'tmp')}) | ||
14 | print("In lane 2:", table.unpack{pcall(linda.receive, linda, 'tmp')}) | ||
15 | return 33, 55 | ||
16 | end) | ||
17 | |||
18 | -- send payload twice | ||
19 | linda:send('tmp', payload, payload) | ||
20 | local h = g() | ||
21 | local err, stack = h:join() | ||
22 | print('we reach here and then deadlock', err, stack) | ||
23 | end | ||
24 | -- start lane | ||
25 | |||
26 | -- wait some | ||
27 | lanes.sleep(2) | ||
28 | print('we never reach here') \ No newline at end of file | ||