-
Notifications
You must be signed in to change notification settings - Fork 624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is luasocket thread safe? #175
Comments
I think LuaSocket itself is thread safe. But some functions on some system not thread safe. |
LuaSocket is not thread safe because of buffering on the socket objects. If two threads attempt to read on the same socket, things may go very wrong. There is also the problem that Moteus mentioned. A few of the networking functions we use may or may not be thread safe depending on the OS. One possibility is to try to use the lua_lock and lua_unlock macros surrounding the critical regions to make sure everything is thread safe. Does anyone care to take a stab at it? |
Thanks for your answers! |
Keep in mind that the default macros don't do anything. They must be redefined. LuaThreads used to do this, but there was so little interest that it was discontinued. The problem here is that Lua itself is not thread safe. So there can be only one script running on each Lua context at each time. |
Would it be thread safe for using two different socket connections, each one in a different lane of lualanes.? |
We are developing a software in C++ that makes use of Lua to easily implement some custom functionalities the user may wish to have. The software implements an API to request images in a specified resolution, rotation etc.
In https://github.com/dhlab-basel/Sipi/blob/develop/sipi.init-knora.lua, we implemented a Lua function that is called each time a client makes a request to our API. Each request is handled in a separate thread.
We encountered a Lua problem when a lot of requests were made to our API at the same time. The application crashed. However, when we commented out
requests = require "requests"
, all went fine again.So could it be a problem that
requests
is loaded by separate threads at the same time? Each thread has its own Lua interpreter.I asked the developer of
lua-requests
about this (JakobGreen/lua-requests#9) and he told me that his module depends onluasocket
and that the problem could be there.So I would like to ask you if
luasocket
is thread safe.The text was updated successfully, but these errors were encountered: