• Stars
    star
    143
  • Rank 257,007 (Top 6 %)
  • Language
    C
  • License
    MIT License
  • Created over 13 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Low-Level threads(pthreads or WIN32 threads) for Lua.

About

travis-ci status

A simple Lua wrapper for pthreads & WIN32 threads.

Each thread gets it's own lua_State and there is no shared global state. The parent thread can pass data to a child thread only as parameters when creating the child thread. The child threads can return data back to the parent thread only when it return (i.e. ends). The parent needs to call child:join() to get the return values from a child thread, this call will block until the child thread ends.

The design goals of this module is only provide support for creating new lua_State and running them in a different thread. This module will not provide any methods of thread-to-thread data passing between running threads (i.e. no locks, no shared state).

Thread to Thread communication methods

  • The recommend method of passing data between threads is to use ZeroMQ.

  • Another method is to use sockets library like LuaSocket or Nixio.

Installation

Release 1.2

lua-llthread 1.2 release:

$ sudo luarocks install lua-llthreads

Lastest Git Revision

With LuaRocks 2.0.4.1:

$ sudo luarocks install https://github.com/Neopallium/lua-llthreads/raw/master/rockspecs/lua-llthreads-scm-0.rockspec

With CMake:

$ git clone git://github.com/Neopallium/lua-llthreads.git
$ cd lua-llthreads ; mkdir build ; cd build
$ cmake ..
$ make
$ sudo make install

Example usage

local llthreads = require"llthreads"

local thread_code = [[
	-- print thread's parameter.
	print("CHILD: received params:", ...)
	-- return all thread's parameters back to the parent thread.
	return ...
]]

-- create detached child thread.
local thread = llthreads.new(thread_code, "number:", 1234, "nil:", nil, "bool:", true)
-- start non-joinable detached child thread.
assert(thread:start(true))
-- Use a detatched child thread when you don't care when the child finishes.

-- create child thread.
local thread = llthreads.new(thread_code, "number:", 1234, "nil:", nil, "bool:", true)
-- start joinable child thread.
assert(thread:start())
-- Warning: If you don't call thread:join() on a joinable child thread, it will be called
-- by the garbage collector, which may cause random pauses/freeze of the parent thread.
print("PARENT: child returned: ", thread:join())

local socket = require"socket"
socket.sleep(2) -- give detached thread some time to run.

More Repositories

1

lua-pb

Lua Protocol Buffers
Lua
288
star
2

llvm-lua

Automatically exported from code.google.com/p/llvm-lua
C
152
star
3

lualogging

New maintainer at: https://github.com/lunarmodules/lualogging
Lua
146
star
4

bevy_water

Dynamic ocean material for Bevy.
Rust
135
star
5

lua-handlers

Provides a set of async. callback based handlers for working with raw TCP/UDP socket, ZeroMQ sockets, or HTTP client/server.
Lua
105
star
6

LuaNativeObjects

A Lua bindings generator written in Lua.
Lua
94
star
7

slua

Static lua compiler - Compile Lua code into C code.
C
69
star
8

nixio

System, Networking and I/O library for Lua. This is an unoffical fork of NIXO from: http://luci.subsignal.org/
C
58
star
9

mmap_lowmem

mmap() wrapper to expand MAP_32BIT to use all of the low 4Gbytes of address space.
C
35
star
10

lua-nanomsg

Lua bindings to NanoMsg
Lua
32
star
11

lua-epoll

Lightweight wrapper for epoll.
C
21
star
12

s1vm

Fast Wasm interpreter in Rust
Rust
18
star
13

bevy_shader_graph

Shader graph for Bevy
Rust
18
star
14

lua-clang-cindex

FFI bindings to libclang's CIndex interface.
Lua
12
star
15

websocket-client-go

Reconnecting Websocket Client Golang Library
Go
12
star
16

lua-llnet

A low-level network IO library.
C
12
star
17

lua-buf

Mutable buffer object for Lua.
C
10
star
18

luagit2

LuaGit2 has move to a new home at https://github.com/libgit2/luagit2
Lua
10
star
19

lua-http-tokenizer

A HTTP protocol tokenizer
C
8
star
20

node_engine

Rust
8
star
21

lludp_dissector

Wireshark dissector for the LLUDP protocol
Lua
6
star
22

jpeg2k

Safe wrapper for openjpeg-sys.
Rust
6
star
23

luaxcb

Lua bindings for XCB
C
4
star
24

bevy_fake_interior

Fake interior material for Bevy
WGSL
4
star
25

nft_trader

NFT trader for Polymesh
TypeScript
4
star
26

serialization-benchmarks

Benchmark comparison of C/C++ serialization systems.
C
3
star
27

cr-sys

Rust raw bindings for cr.h: A Simple C Hot Reload Header-only Library
Rust
2
star
28

lua-net-bench

Network service benchmark/stress-testing suite written in Lua.
Lua
2
star
29

mongrel2_stream_prototype

Prototype a stream interface between mongrel2 and backend handlers.
Lua
2
star
30

faxpp

Fast XML Pull Parser
C
2
star
31

sub-script

Scripting interface for substrate nodes.
Rust
2
star
32

cr-rs

Rust safe wrapper for cr.h: A Simple C Hot Reload Header-only Library
Rust
2
star
33

lua-http-message

Fast HTTP message parser for Lua.
Lua
2
star
34

n_closure

header-only C Closure library
C++
2
star
35

pusher-client-go

Pusher Client Go Library
Go
1
star
36

material_designer

Designer for working on Materials/Shaders for Bevy
Rust
1
star
37

openjp2

Rust port of OpenJpeg
C
1
star