From 2b985e277f06a7086025ab292ddb22b5ded89189 Mon Sep 17 00:00:00 2001 From: ame Date: Thu, 9 May 2024 10:31:26 -0500 Subject: work on memory saftey --- docs/thread.md | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) (limited to 'docs/thread.md') diff --git a/docs/thread.md b/docs/thread.md index 0c8de77..9f868cb 100644 --- a/docs/thread.md +++ b/docs/thread.md @@ -28,12 +28,14 @@ llib.thread.unlock(5) t:await() ``` -## aync ** +## aync 'takes a function which will be ran in a separate thread with a single parameter with thread info these have the same backend (and limitations) of network threads +the rej (2nd param) is currently unused + ```lua local thread = llib.thread.async(function(res, rej) local N = 0 @@ -42,7 +44,7 @@ local thread = llib.thread.async(function(res, rej) end) ``` -### thread function parameters ** +### thread function parameters as used with "res" above @@ -52,17 +54,6 @@ as used with "res" above send a value(s) to thread:await() call then stalls the thread until cleaned -#### res:send() ** - -'takes "any" value - -send a value which can be retrieved from outside the thread with thread:next() - -```lua -res:send(5) -res:send("hello") -``` - ### thread return object ** #### thread:await() ** @@ -70,31 +61,20 @@ res:send("hello") 'optional timeout in ms and boolean whether to keep or not waits for the thread to return, and returns whatever it returned then closes it, or nil if timeout was exceeded -if the input is the boolean value true, it will keep the thread alive (otherwise await() can not be called again) ```lua thread:await() -- value of N (above) ``` ```lua -thread:await(20) -- value of N (above) or nil -``` - -```lua -thread:await(true) -- value of N (above) -thread:await() -- same -thread:await() -- error, function above performed cleanup +thread:await(20) -- value of N (above) or nil and preserves the thread ``` -#### thread:next() ** +#### thread:clean() ** -gets the most oldest value sent using info:send() and pops it +frees everything related to the thread (including userdata allocated in it!), thread:await() can not be called again, all lua values will still be usable -```lua ---(continued from above) -thread:next() -- 5 -thread:next() -- "hello" -``` +not required to be called, lua gc should call it on its own via __gc #### thread:kill() ** -- cgit v1.2.3