lunarmodules / luasql

LuaSQL is a simple interface from Lua to a DBMS.
http://lunarmodules.github.io/luasql
535 stars 192 forks source link

Using luasql-sqlite3 in multithreaded applications #88

Open Aditya23456 opened 6 years ago

Aditya23456 commented 6 years ago

Hi,

I am using Lua lanes to run 3 threads. I am using luasqlite-3 database to store the data collected by these threads. I can have my 3 threads independently reading data simultaneously from the db but when I try to write on db from more than 1 thread I get "LuaSQL: database is locked thread: 0xb6f35c10 tcp{client}: 0xb6e8f1a0" error. Is Luasqlite-3 threadsafe? The only way I see is to write a separate thread dedicated for db connections and make other threads send data to it. This is not scalable and requires many implementation details. Also, I have written an independent script which accesses the database for readings and runs as a separate process. Even this independent script can't access the sqllite database when my multithreaded application is running and gives error LuaSQL: database is locked. I read online that compiling SQLite with the threadsafe tag or configuring it during runtime will help. Can anyone put some light on how to make Luasqlite-3 multi-threaded? I see all 3 threads have different environment object. Thanks, Aditya