m4 macro to check if SQLite was compiled thread-safe

If your application is using SQLite, you may be assuming it is always compiled thread-safe, but this is not true. It will only be compiled thread-safe (with proper mutexes enabled) if the SQLITE_THREADSAFE preprocessor macro is set to 1 (serialized) or 2 (multi-threaded) (1/serialized is the default if not explicitly stated). If SQLITE_THREADSAFE is set to 0 during compilation of SQLite, it will not be thread-safe. Also note that if compiled thread-safe (1 or 2), the thread-safety mode (serialized or multi-threaded) can later be changed in runtime. See SQLite and Multiple Threads for more information.

SQLite provides the sqlite3_threadsafe() method to check whether the library was compiled thread-safe, but if your application really needs a thread-safe SQLite, you don’t want to check it during runtime. Thus, I wrote a small m4 macro that you can use in your configure.ac to check it when running ./configure

Just add this file in your m4 directory:

And then, in your configure.ac:

if test "x$ax_cv_sqlite_threadsafe" != "xyes"; then
  AC_MSG_ERROR([sqlite3 is not compiled thread-safe])

Posted on October 5, 2010, in Development and tagged , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: