I have a large deployment of thousands of SQLite databases accessed from the same multi-threaded process, and up until recently, I didn't even consider thread safety, because
1) I only ever talk to a SQLite database connection from one thread at a time, and 2) I am dumb. I do maintain SQLite database connections from threadpools, and so, often, I am jumping the connection between threads within the threadpool, with open transactions, prepared statements, etc, though never concurrently. I was just pointed to http://www.sqlite.org/faq.html#q6 We are using SQLite 3.6.22 on Debian Etch (sadness), and I just wrote some test code around using fcntl to lock and unlock a file from different threads, and I can't seem to get it to break, nor have we seen any trouble with our deployment. So, my questions are: 1) Did we somehow magically avoid this bullet? 2) What situations with fcntl in multiple threads cause sadness? 3) Is Etch a "troublesome system"? 4) What would failures in this scenario look like? Are we risking corruption? My test code is Python, but Python uses native fcntl and pthreads in the interpreter to implement its modules, so this should be similar to what we're doing in our deployment. I run these two python scripts concurrently on Etch and it works as expected. #!/usr/bin/python import fcntl, threading, time f = file("/tmp/test-fcntl", 'w') def thread1(): fcntl.lockf(f.fileno(), fcntl.LOCK_EX) print "locked" time.sleep(5) def thread2(): time.sleep(5) print "unlocking" fcntl.lockf(f.fileno(), fcntl.LOCK_UN) print "unlocked" threads = [threading.Thread(target=t) for t in (thread1, thread2)] for thread in threads: thread.start() for thread in threads: thread.join() # make sure other process locks when we unlock and not when we exit time.sleep(3) #!/usr/bin/python import fcntl, time time.sleep(1) f = file("/tmp/test-fcntl", 'w') print "locking 2" fcntl.lockf(f.fileno(), fcntl.LOCK_EX) print "locked 2" Thanks -JT _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users