3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
12 # $Id: thread004.test,v 1.3 2009/06/05 17:09:12 drh Exp $
14 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 if {[run_thread_tests]==0} { finish_test ; return }
18 ifcapable !shared_cache {
22 if { [info commands sqlite3_table_column_metadata] eq "" } {
27 # Use shared-cache mode for this test.
30 set ::enable_shared_cache [sqlite3_enable_shared_cache]
31 sqlite3_enable_shared_cache 1
33 # Create a table in database test.db
36 do_test thread004-1.1 {
37 execsql { CREATE TABLE t1(a, b, c) }
40 do_test thread004-1.2 {
43 set iStart [clock_seconds]
44 while {[clock_seconds]<$iStart+20} {
45 set ::DB [sqlite3_open test.db]
50 set ::DB [sqlite3_open test.db]
51 set iStart [clock_seconds]
53 while {[clock_seconds] <$iStart+20} {
54 incr nErr [catch {sqlite3_table_column_metadata $::DB main t1 a}]
60 # Run two threads. The first thread opens and closes database test.db
61 # repeatedly. Each time this happens, the in-memory schema used by
62 # all connections to test.db is discarded.
64 # The second thread calls sqlite3_table_column_metadata() over and
65 # over again. Each time it is called, the database schema is loaded
66 # if it is not already in memory. At one point this was crashing.
68 unset -nocomplain finished
69 thread_spawn finished(1) $thread_procs $ThreadOne
70 thread_spawn finished(2) $thread_procs $ThreadTwo
73 if {![info exists finished($t)]} { vwait finished($t) }
78 sqlite3_enable_shared_cache $::enable_shared_cache