Amalgamation compilation with SQLITE_THREADSAFE=0

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

Amalgamation compilation with SQLITE_THREADSAFE=0

Jacky Lam
Hi All,
I am currently doing amalgamation compilation of SQLite and target for low
computational power, portable, single thread devices.
The OS version used in these devices are the very simplified version of
Linux OS. More specifically, it does not have pthread, mutex and
mutli-threading related functions. it has its own specific file system.

Hence to let the SQLite compiles successfully, I set the following MACRO
during compilation:
SQLITE_OS_OTHER=1
SQLITE_THREADSAFE=0
SQLITE_OMIT_LOAD_EXTENSION=1
SQLITE_OMIT_MEMORYDB=1

I would like to know
1. Can I call sqlite3_open more than one times before calling sqlite3_close
and sqlite3_free?
2. If the above mentioned devices change to mutli-thread setting but no
thread safe functions such as mutex, is this setting still fine?
     If not, how can I make it thread safe with lack of mutex support in
the system?

Thanks.

Jacky
_______________________________________________
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: Amalgamation compilation with SQLITE_THREADSAFE=0

Simon Slavin-3


On 9 Aug 2017, at 3:31am, Jacky Lam <[hidden email]> wrote:

> 1. Can I call sqlite3_open more than one times before calling sqlite3_close
> and sqlite3_free?

Call sqlite3_open() for each database you want to open.  You can have any number of databases open at the same time.  Call sqlite3_close() for each database you have open when you no longer need it.  After closing the last connection call sqlite3_shutdown() as described in

<https://sqlite.org/c3ref/initialize.html>

(The above ignores use of SQL's ATTACH command.)

You are not expected to ever call sqlite3_free() unless you are using SQLite to do other memory-handing tasks for you.  Most people who use SQLite never call sqlite3_free().

> 2. If the above mentioned devices change to mutli-thread setting but no
> thread safe functions such as mutex, is this setting still fine?

You have explicitly declared SQLITE_THREADSAFE=0 .  That means you will arrange that only one thread will be doing SQLite calls at once.  As long as you can ensure this, SQLite will function correctly.

>     If not, how can I make it thread safe with lack of mutex support in
> the system?

Do any of the following:

A) Implement your own mutex system.

B) Use SQLite’s mutex system ( <https://sqlite.org/c3ref/mutex_alloc.html> )

C) Supply the value SQLITE_OPEN_FULLMUTEX when you open connections using sqlite3_open_v2(), as described in <https://sqlite.org/c3ref/open.html> .

Please note that the above is a top-of-the-head answer and I have not personally tries each of the options to make sure it works.

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