diff options
author | Alexey Melnichuk <mimir@newmail.ru> | 2014-02-04 11:06:17 +0400 |
---|---|---|
committer | Alexey Melnichuk <mimir@newmail.ru> | 2014-02-04 11:06:17 +0400 |
commit | cef9a7a112a8322e2c6498021df59e4a8f7b5246 (patch) | |
tree | 5a885427afef52cbd3067c79b1f24406e42ecf87 /README.md | |
parent | d35bf824e0dd9c3584d1587b5ec662a0fcf71bfe (diff) | |
download | lua-llthreads2-cef9a7a112a8322e2c6498021df59e4a8f7b5246.tar.gz lua-llthreads2-cef9a7a112a8322e2c6498021df59e4a8f7b5246.tar.bz2 lua-llthreads2-cef9a7a112a8322e2c6498021df59e4a8f7b5246.zip |
Add. `thread:alive()` method.
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -13,6 +13,7 @@ This is full dropin replacement for [llthreads](https://github.com/Neopallium/lu | |||
13 | ##Additional | 13 | ##Additional |
14 | * thread:join() method support zero timeout to check if thread alive (does not work on Windows with pthreads) | 14 | * thread:join() method support zero timeout to check if thread alive (does not work on Windows with pthreads) |
15 | * thread:join() method support arbitrary timeout on Windows threads | 15 | * thread:join() method support arbitrary timeout on Windows threads |
16 | * thread:alive() method return whether the thread is alive (does not work on Windows with pthreads) | ||
16 | * set_logger function allow logging errors (crash Lua VM) in current llthread's threads | 17 | * set_logger function allow logging errors (crash Lua VM) in current llthread's threads |
17 | * thread:start() has additional parameter which control in which thread child Lua VM will be destroyed | 18 | * thread:start() has additional parameter which control in which thread child Lua VM will be destroyed |
18 | * allow pass cfunctions to child thread (e.g. to initialize Lua state) | 19 | * allow pass cfunctions to child thread (e.g. to initialize Lua state) |
@@ -89,5 +90,22 @@ llthreads.new([[ | |||
89 | ]], preload):start(true) | 90 | ]], preload):start(true) |
90 | ``` | 91 | ``` |
91 | 92 | ||
93 | ### Wait while thread is alive | ||
94 | ``` Lua | ||
95 | local thread = require "llthreads".new[[ | ||
96 | require "utils".sleep(5) | ||
97 | return 1 | ||
98 | ]] | ||
99 | thread:start() | ||
100 | |||
101 | -- we can not use `thread:join(0)` because we can not call it twice | ||
102 | -- so all returned vaules will be lost | ||
103 | while thread:alive() do | ||
104 | -- do some work | ||
105 | end | ||
106 | |||
107 | local ok, ret = thread:join() -- true, 1 | ||
108 | ``` | ||
109 | |||
92 | [](https://bitdeli.com/free "Bitdeli Badge") | 110 | [](https://bitdeli.com/free "Bitdeli Badge") |
93 | 111 | ||