1 # 2009 February 26 2 # 3 # The author disclaims copyright to this source code. In place of 4 # 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 14 set testdir [file dirname $argv0] 15 16 source $testdir/tester.tcl 17 if {[run_thread_tests]==0} { finish_test ; return } 18 ifcapable !shared_cache { 19 finish_test 20 return 21 } 22 if { [info commands sqlite3_table_column_metadata] eq "" } { 23 finish_test 24 return 25 } 26 27 # Use shared-cache mode for this test. 28 # 29 db close 30 set ::enable_shared_cache [sqlite3_enable_shared_cache] 31 sqlite3_enable_shared_cache 1 32 33 # Create a table in database test.db 34 # 35 sqlite3 db test.db 36 do_test thread004-1.1 { 37 execsql { CREATE TABLE t1(a, b, c) } 38 } {} 39 40 do_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 $::DB 47 } 48 } 49 set ThreadTwo { 50 set ::DB [sqlite3_open test.db] 51 set iStart [clock_seconds] 52 set nErr 0 53 while {[clock_seconds] <$iStart+20} { 54 incr nErr [catch {sqlite3_table_column_metadata $::DB main t1 a}] 55 } 56 sqlite3_close $::DB 57 set nErr 58 } 59 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. 63 # 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. 67 # 68 unset -nocomplain finished 69 thread_spawn finished(1) $thread_procs $ThreadOne 70 thread_spawn finished(2) $thread_procs $ThreadTwo 71 72 foreach t {1 2} { 73 if {![info exists finished($t)]} { vwait finished($t) } 74 } 75 76 set finished(2) 77 } {0} 78 sqlite3_enable_shared_cache $::enable_shared_cache 79 finish_test 80