aboutsummaryrefslogtreecommitdiff
path: root/docs/thread
diff options
context:
space:
mode:
Diffstat (limited to 'docs/thread')
-rw-r--r--docs/thread/async.md51
-rw-r--r--docs/thread/buffer.md31
-rw-r--r--docs/thread/mutex.md23
-rw-r--r--docs/thread/usleep.md5
4 files changed, 110 insertions, 0 deletions
diff --git a/docs/thread/async.md b/docs/thread/async.md
new file mode 100644
index 0000000..a13b18b
--- /dev/null
+++ b/docs/thread/async.md
@@ -0,0 +1,51 @@
+## async
+
+thread.async(function(res))
+
+despite the name, this function provides a new state running under a new thread. coroutines would be more what you are looking for for async
+
+the argument function is executed by the thread until it has been completed. the res paramater is a function that takes any number of arguments and sets them as the value for the thread:await() call, and kills the thread (safely)
+
+the reason for the res function it because lua_call (in the c api) requires a number or return values before you run the function
+
+the res function also provides some child methods for thread managment
+
+though variables are copied, some may not be able to clone perfectly (complex userdata, lightuserdata, etc..) and the __gc call from the main thread may effect the copy on the new thread. this issue wont be permanent, but it may require a workaround for now.
+
+### res:testclose
+
+res:testclose()
+
+closes the thread if it is being requested to close from async:close
+
+### res:autoclose
+
+res:autoclose()
+
+calls res:testclose() every lua line, using a debug hook
+
+---
+
+### async:await
+
+async:await()
+
+pauses the current thread until the selected thread exits, or calls res(), the return value is whatever the thread passed to res
+
+### async:kill
+
+async:kill()
+
+kills the thread, this may close it in an unsafe way, and should be avoided
+
+### async:close
+
+async:close()
+
+waits for the thread to internally call res:testclose or exit
+
+### async:clean
+
+async:clean()
+
+calls the __gc metamethod, will call async:kill() if it is still running
diff --git a/docs/thread/buffer.md b/docs/thread/buffer.md
new file mode 100644
index 0000000..e366a33
--- /dev/null
+++ b/docs/thread/buffer.md
@@ -0,0 +1,31 @@
+## buffer
+
+thread.buffer(V)
+
+a buffer is a container that allows a variable to be shared between threads & states in a thread safe manor.
+
+it is able to store 'anything' though lightuserdata will likely not work properly. poorly structured user data may retain some shared state with the original, which could cause some use-after-free in some really poor situations. providing a __copy metamethod will alleviate this issue (read more in readme.md)
+
+the __gc metamethod will be stripped from the original object and called when the buffer's __gc gets called. you should not reuse the original object after putting in a buffer for this reason.
+
+the __index metamethod will index any value that is not a buffer.* method on the original object (i will try not to add any more)
+
+every other metamethod will be replaced with a proxy to the metamethod in the copied object
+
+### buffer:get
+
+buffer:get()
+
+copies the value in the buffer to the current state
+
+### buffer:set
+
+buffer:set(V)
+
+sets the value in the buffer
+
+### buffer:mod
+
+buffer:mod(function(V))
+
+takes a function with a single argument (the value), the return value of this will be the new value, if it is nil, the value will return unchanged
diff --git a/docs/thread/mutex.md b/docs/thread/mutex.md
new file mode 100644
index 0000000..09acd77
--- /dev/null
+++ b/docs/thread/mutex.md
@@ -0,0 +1,23 @@
+## mutex
+
+thread.mutex()
+
+creates a pthread_mutex
+
+### mutex:lock
+
+mutex:lock()
+
+locks the mutex
+
+### mutex:unlock
+
+mutex:unlock()
+
+you'll never guess what this one does (unlocks the mutex)
+
+### mutex:free
+
+mutex:free()
+
+calls the __gc method
diff --git a/docs/thread/usleep.md b/docs/thread/usleep.md
new file mode 100644
index 0000000..75208a9
--- /dev/null
+++ b/docs/thread/usleep.md
@@ -0,0 +1,5 @@
+## usleep
+
+thread.usleep(μN)
+
+puts the thread to sleep for N microseconds (duh)