LuaThread
Multi-(platform|threading) support for the Lua language

download · installation · examples · reference


What is LuaThread?

LuaThread enables the Lua programmer to create preemptive, concurrent Lua programs, in which several threads of execution coordinately perform different tasks in parallel. The library runs both on Unix systems supporting the Pthreads standard and on Win32 systems (natively).

The functionality is provided in two parts: routines needed by Lua core to control parallel access to its internal structures and, independently, functions providing Lua scripts with the ability to create and synchronize multiple threads of execution.

Since the first part of the library is tightly integrated to the Lua core implementation, LuaThread requires that the Lua library be entirely recompiled before it can be used by client scripts. This process is detailed in the build instructions.

The second part of the library provides client support for the manipulation of threads as well as mutex and condition synchronization objects. The LuaThread API follows the Pthreads standard closely, as detailed in the reference manual.

The library is available under the same terms and conditions as the Lua language, the MIT license. The idea is that if you can use Lua in a project, you should also be able to use LuaThread.

Copyright © 2004 Diego Nehab. All rights reserved.
Author: Diego Nehab

Download

LuaThread version 1.1 alpha is now available for download! It is compatible with Lua 5.0 and has been tested on Windows XP, Linux, and Mac OS X.

The library can be downloaded in source code from the following links:

luathread-1.1-alpha.tar.gz
luathread-1.1-alpha.zip

Besides the full C and Lua source code for the library, the distribution contains several examples and this user's manual.

I am also providing PC Win32 binaries for those that want to give LuaThread a quick try:

luathread-1.1-alpha-win32.zip

The quick and dirty way to use these binaries is to unpack everything into a directory, say c:\luathread, then set LUA_INIT to load the compat-5.1.lua and set LUA_PATH and LUA_CPATH to look for files in the current directory:

c:\luathread\> set LUA_INIT=@c:\luathread\compat-5.1.lua
c:\luathread\> set LUA_CPATH=?.dll
c:\luathread\> set LUA_PATH=?.lua

From that directory, you can then run the interpreter and it should find all files it needs.

c:\luathread\> lua
Lua 5.0.2 + LuaThread 1.1 (alpha)  Copyright (C) 1994-2004 Tecgraf, PUC-Rio
> thread = require"thread"
> print(thread.VERSION)
LuaThread 1.1 (alpha)