AryaWu/sqlite
0
1# 2009 February 262#3# The author disclaims copyright to this source code. In place of4# a legal notice, here is a blessing:5#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.9#10#***********************************************************************11#12# $Id: thread004.test,v 1.3 2009/06/05 17:09:12 drh Exp $13 14set testdir [file dirname $argv0]15 16source $testdir/tester.tcl17if {[run_thread_tests]==0} { finish_test ; return }18ifcapable !shared_cache {19 finish_test20 return21}22if { [info commands sqlite3_table_column_metadata] eq "" } {23 finish_test24 return25}26 27# Use shared-cache mode for this test.28# 29db close30set ::enable_shared_cache [sqlite3_enable_shared_cache]31sqlite3_enable_shared_cache 132 33# Create a table in database test.db34#35sqlite3 db test.db36do_test thread004-1.1 {37 execsql { CREATE TABLE t1(a, b, c) }38} {}39 40do_test thread004-1.2 {41 42 set ThreadOne {43 set iStart [clock_seconds]44 while {[clock_seconds]<$iStart+20} {45 set ::DB [sqlite3_open test.db]46 sqlite3_close $::DB47 }48 }49 set ThreadTwo {50 set ::DB [sqlite3_open test.db]51 set iStart [clock_seconds]52 set nErr 053 while {[clock_seconds] <$iStart+20} {54 incr nErr [catch {sqlite3_table_column_metadata $::DB main t1 a}]55 }56 sqlite3_close $::DB57 set nErr58 }59 60 # Run two threads. The first thread opens and closes database test.db61 # repeatedly. Each time this happens, the in-memory schema used by62 # all connections to test.db is discarded.63 #64 # The second thread calls sqlite3_table_column_metadata() over and65 # over again. Each time it is called, the database schema is loaded66 # if it is not already in memory. At one point this was crashing.67 #68 unset -nocomplain finished69 thread_spawn finished(1) $thread_procs $ThreadOne70 thread_spawn finished(2) $thread_procs $ThreadTwo71 72 foreach t {1 2} {73 if {![info exists finished($t)]} { vwait finished($t) }74 }75 76 set finished(2)77} {0}78sqlite3_enable_shared_cache $::enable_shared_cache79finish_test80 