Quantcast

Multithread

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Multithread

Наиль Шигапов

Hellow!

I write small orm based on sqlite database from ios - application! I have one or more question about multi-thread in sqlite.
Today for fetch or write information from different thread, i lock thread if database is lock(write, read,e.t.c) But i don’t want lock my thread. I read from documentation about «vfs» technology in sqlite. Does it make sense to create vfs object and write information there, while database lock, and then write information if the database unlock.

Thanks,
Nail.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multithread

Jens Alfke-2

> On Mar 6, 2017, at 7:10 AM, Наиль Шигапов <[hidden email]> wrote:
>
> Today for fetch or write information from different thread, i lock thread if database is lock(write, read,e.t.c) But i don’t want lock my thread. I read from documentation about «vfs» technology in sqlite. Does it make sense to create vfs object and write information there, while database lock, and then write information if the database unlock.

No, the VFS API is for implementing your own storage layer underneath SQLite. It wouldn’t help with multithreading.

If you want multiple threads to be able to read from the database simultaneously, then your best bet is to create a small pool of SQLite connections and have the thread grab a connection from the pool, do its work, then return the connection.

Also, you should enable WAL mode, so you’ll be able to read from the database while another connection is writing.

There’s nothing you can do about multiple simultaneous writes, though — SQLite allows only a single connection to have a write-lock on the db at a time.

—Jens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Loading...