diff options
author | moteus <mimir@newmail.ru> | 2013-12-26 18:52:58 +0400 |
---|---|---|
committer | moteus <mimir@newmail.ru> | 2013-12-26 18:52:58 +0400 |
commit | e3fe5123a36643634e00de6a1bb940e6e1febade (patch) | |
tree | 8eecc3aa10e8c6842efe1d798758942f35f555f6 /README.md | |
parent | 5291caae5be68250a4d9aafa54fe2081ab2a6113 (diff) | |
download | lua-llthreads2-e3fe5123a36643634e00de6a1bb940e6e1febade.tar.gz lua-llthreads2-e3fe5123a36643634e00de6a1bb940e6e1febade.tar.bz2 lua-llthreads2-e3fe5123a36643634e00de6a1bb940e6e1febade.zip |
Add. `joinable` parameter to `start` method which control in which thread child Lua VM will be destroyed.
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -16,6 +16,7 @@ This is full dropin replacement for [llthreads](https://github.com/Neopallium/lu | |||
16 | * thread:join() method support zero timeout to check if thread alive | 16 | * thread:join() method support zero timeout to check if thread alive |
17 | * thread:join() method support arbitrary timeout on Windows platform | 17 | * thread:join() method support arbitrary timeout on Windows platform |
18 | * set_logger function allow logging errors (crash Lua VM) in current llthread's threads | 18 | * set_logger function allow logging errors (crash Lua VM) in current llthread's threads |
19 | * thread:start() has additional parameter which control in which thread child Lua VM will be destroyed | ||
19 | 20 | ||
20 | ##Usage | 21 | ##Usage |
21 | 22 | ||
@@ -33,5 +34,45 @@ llthread.set_logger(function(msg) LOG.error(msg) end) | |||
33 | error("SOME ERROR") | 34 | error("SOME ERROR") |
34 | ``` | 35 | ``` |
35 | 36 | ||
37 | ### Start atached thread collectd in child thread | ||
38 | ``` Lua | ||
39 | -- This is main thread. | ||
40 | local thread = require "llthreads".new[[ | ||
41 | require "utils".sleep(5) | ||
42 | ]] | ||
43 | |||
44 | -- We tell that we start atached thread | ||
45 | -- but child Lua State shuld be close | ||
46 | -- in child thread. | ||
47 | -- So thread:join() can not return any values. | ||
48 | -- If `thread` became garbage in main thread then | ||
49 | -- finallizer calls thread:join() and main thread | ||
50 | -- may hungup. | ||
51 | thread:start(false, false) | ||
52 | |||
53 | -- we can call join | ||
54 | thread:join() | ||
55 | ``` | ||
56 | |||
57 | ### Start detached thread collectd on which we can call join | ||
58 | ``` Lua | ||
59 | -- This is main thread. | ||
60 | local thread = require "llthreads".new[[ | ||
61 | require "utils".sleep(5) | ||
62 | ]] | ||
63 | |||
64 | -- We tell that we start detached thread | ||
65 | -- but with ability call thread:join() | ||
66 | -- and gets lua return values from child thread. | ||
67 | -- In fact we start atached thread but if `thread` | ||
68 | -- became garbage in main thread then finallizer | ||
69 | -- just detach child thread and main thread | ||
70 | -- may not hungup. | ||
71 | thread:start(true, true) | ||
72 | |||
73 | -- we can call join | ||
74 | thread:join() | ||
75 | ``` | ||
76 | |||
36 | [](https://bitdeli.com/free "Bitdeli Badge") | 77 | [](https://bitdeli.com/free "Bitdeli Badge") |
37 | 78 | ||