Documentation Source Text

Check-in [44c2594627]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the threadsafe.html document and related documentation changes.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 44c25946278af3984d948e6cc8fb13a17cbb4104
User & Date: drh 2008-09-02 21:34:14
Context
2008-09-04
09:26
Enhance the description of the SQLITE_ENABLE_LOCKING_STYLE option in compile.html. check-in: 523d4bcf07 user: dan tags: trunk
2008-09-02
21:34
Add the threadsafe.html document and related documentation changes. check-in: 44c2594627 user: drh tags: trunk
13:34
Documentation changes for 3.6.2 check-in: 208918a3f1 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to pages/compile.in.

131
132
133
134
135
136
137
138
139
140
141
142
143



144
145
146
147
148

149
150
151






152
153
154
155
156
157
158
...
603
604
605
606
607
608
609












610
611
612
613
614
615
616
  might be recoverable from a database using a binary editor.
  However, there is a performance penalty for using this option.

  This option does <u>not</u> cause deleted data is securely
  removed from the underlying storage media.
}

COMPILE_OPTION {SQLITE_THREADSAFE=<i>&lt;0 or 1&gt;</i>} {
  This option controls whether or not code is included in SQLite to
  enable it to operate safely in a multithreaded environment.  The
  default is SQLITE_THREADSAFE=1 which is safe for use in a multithreaded
  environment.  When compiled with SQLITE_THREADSAFE=0 all mutexing code
  is omitted and it is unsafe to use SQLite in a multithreaded program.




  The value of SQLITE_THREADSAFE can be determined at run-time
  using the [sqlite3_threadsafe()] interface.

  When SQLite has been compiled with SQLITE_THREADSAFE=1 then mutexing

  can be disabled at run-time using the [sqlite3_config()] interface together
  with the [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD], and
  [SQLITE_CONFIG_SERIALIZED] verbs.






}

COMPILE_OPTION {SQLITE_TEMP_STORE=<i>&lt;0 through 3&gt;</i>} {
  This option controls whether temporary files are stored on disk or
  in memory.  The meanings for various settings of this compile-time
  option are as follows:

................................................................................
  for which the schema contains VIEW objects. 
}

COMPILE_OPTION {SQLITE_OMIT_VIRTUALTABLE} {
  This option omits support for the [sqlite3_vtab | Virtual Table]
  mechanism in SQLite.
}













COMPILE_OPTION {SQLITE_OMIT_XFER_OPT} {
  This option omits support for optimizations that help statements
  of the form "INSERT INTO ... SELECT ..." run faster.
}

</tcl>







|





>
>
>




|
>
|

|
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>







131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
...
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
  might be recoverable from a database using a binary editor.
  However, there is a performance penalty for using this option.

  This option does <u>not</u> cause deleted data is securely
  removed from the underlying storage media.
}

COMPILE_OPTION {SQLITE_THREADSAFE=<i>&lt;0 or 1 or 2&gt;</i>} {
  This option controls whether or not code is included in SQLite to
  enable it to operate safely in a multithreaded environment.  The
  default is SQLITE_THREADSAFE=1 which is safe for use in a multithreaded
  environment.  When compiled with SQLITE_THREADSAFE=0 all mutexing code
  is omitted and it is unsafe to use SQLite in a multithreaded program.
  When compiled with SQLITE_THREADSAFE=2, SQLite can be used in a multithreaded
  program so long as no two threads attempt to use the same
  [database connection] at the same time.

  The value of SQLITE_THREADSAFE can be determined at run-time
  using the [sqlite3_threadsafe()] interface.

  When SQLite has been compiled with SQLITE_THREADSAFE=1 or
  SQLITE_THREADSAFE=2 then the [threading mode]
  can be altered at run-time using the [sqlite3_config()] interface together
  with the [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD], and
  [SQLITE_CONFIG_SERIALIZED] verbs.  The [SQLITE_OPEN_NOMUTEX] and
  [SQLITE_OPEN_FULLMUTEX] flags to [sqlite3_open_v2()] can also be used
  to adjust the [threading mode] of individual [database connections]
  at run-time.

  See the [threading mode] documentation for additional information
  on aspects of using SQLite in a multithreaded environment.
}

COMPILE_OPTION {SQLITE_TEMP_STORE=<i>&lt;0 through 3&gt;</i>} {
  This option controls whether temporary files are stored on disk or
  in memory.  The meanings for various settings of this compile-time
  option are as follows:

................................................................................
  for which the schema contains VIEW objects. 
}

COMPILE_OPTION {SQLITE_OMIT_VIRTUALTABLE} {
  This option omits support for the [sqlite3_vtab | Virtual Table]
  mechanism in SQLite.
}

COMPILE_OPTION {SQLITE_OMIT_WSD} {
  This options builds a version of the SQLite library that contains no
  Writable Static Data (WSD).  WSD is global variables and/or static
  variables.  Some platforms do not support WSD, and this option is necessary
  in order for SQLite to work those platforms.  

  Unlike other OMIT options which make the SQLite library smaller,
  this option actually increases the size of SQLite and makes it run
  a little slower.  Only use this option if SQLite is being built for an
  embedded target that does not support WSD.
}

COMPILE_OPTION {SQLITE_OMIT_XFER_OPT} {
  This option omits support for optimizations that help statements
  of the form "INSERT INTO ... SELECT ..." run faster.
}

</tcl>

Added pages/threadsafe.in.







































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<title>Using SQLite In Multi-Threaded Applications</title>
<tcl>hd_keywords {threading mode}</tcl>

<h2>SQLite And Multiple Threads</h2>

<p>SQLite support three different threading modes:</p>

<ol>
<li><p><b>Single-thread</b>.
In this mode, all mutexes are disabled and SQLite is unsafe to use in
more than a single thread at once.</p></li>

<li><p><b>Multi-thread</b>.
In this mode, SQLite can be safely used by multiple threads provided that
no single database connection is used simulataneously in two or more threads.
</p></li>

<li><p><b>Serialized</b>.
In serialized mode, SQLite can be safely used by multiple threads with no
restriction.</p></li>
</ol>

<p>
The threading mode can be selected at compile-time (when the SQLite
library is being compiled from source code) or at start-time (when the
application that intends to use SQLite is initializing) or at
run-time (when a new SQLite database connection is being created).
Generally speaking, run-time overrides start-time and start-time
overrides compile-time.  Except, single-thread mode cannot be 
overridden once selected.
</p>

<p>
The default mode is serialized.
</p>

<h3>Compile-time selection of threading mode</h3>

<p>
Use the [SQLITE_THREADSAFE] compile-time parameter to selected the
threading mode.  If no [SQLITE_THREADSAFE] compile-time parameter is
present, then serialized mode is used.
This can be made explicit with 
[SQLITE_THREADSAFE | -DSQLITE_THREADSAFE=1].
With
[SQLITE_THREADSAFE | -DSQLITE_THREADSAFE=0] the threading mode is
single-thread.  With
[SQLITE_THREADSAFE | -DSQLITE_THREADSAFE=2] the threading mode is
multi-thread.
</p>

<p>
The return value of the [sqlite3_threadsafe()] interface is determined
by the compile-time threading mode selection.  If single-thread mode
is selected at compile-time, then [sqlite3_threadsafe()] returns false.
If either the multi-thread or serialized modes are selected, then
[sqlite3_threadsafe()] returns true.  The [sqlite3_threadsafe()]
interface predates the multi-thread mode and start-time and run-time
mode selection and so is unable to distinguish
between multi-thread and serialized mode nor is it able to report start-time
or run-time mode changes.
</p>

<p>
If single-thread mode is selected at compile-time, then critical
mutexing logic is omitted from the build and it is impossible to
enable either multi-thread or serialized modes at start-time or
run-time.
</p>

<h3>Start-time selection of threading mode</h3>

<p>
Assuming that the compile-time threading mode is not single-thread, then
the threading mode can be changed during initialization using the
[sqlite3_config()] interface.  The [SQLITE_CONFIG_SINGLETHREAD] verb
puts SQLite into single-thread mode, the [SQLITE_CONFIG_MULTITHREAD]
verb sets multi-thread mode, and the [SQLITE_CONFIG_SERIALIZED] verb
sets serialized mode.
</p>

<h3>Run-time selection of threading mode</h3>

<p>If single-thread mode has not been selected at compile-time or start-time,
then individual database connections can be created as either multi-thread
or serialized.  It is not possible to downgrade an individual database
connection to single-thread mode.  Nor is it possible to escalate an
individual database connection if the compile-time or start-time mode
is single-thread.</p>

<p>The threading mode for an individual database connection is determined
by flags given as the third argument to [sqlite3_open_v2()].  The
[SQLITE_OPEN_NOMUTEX] flag causes the database connection to be in the
multi-thread mode and the [SQLITE_OPEN_FULLMUTEX] flag causes the connection
to be in serialized mode.  If neither flag is specified or if
[sqlite3_open()] or [sqlite3_open16()] are used instead of 
[sqlite3_open_v2()], then the default
mode determined by the compile-time and start-time settings is used.
</p>