mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-27 20:41:58 +03:00
In sqlite3_table_column_metadata(), hold the mutex on all attached BtShared objects while accessing schema objects. Fix for #3679. (CVS 6328)
FossilOrigin-Name: d197afd658eecfc0e24913e5a779c8f1e2a138a6
This commit is contained in:
80
test/thread004.test
Normal file
80
test/thread004.test
Normal file
@ -0,0 +1,80 @@
|
||||
# 2009 February 26
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# $Id: thread004.test,v 1.1 2009/02/26 07:15:59 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
|
||||
source $testdir/tester.tcl
|
||||
ifcapable !mutex||!shared_cache {
|
||||
return
|
||||
}
|
||||
source $testdir/thread_common.tcl
|
||||
if {[info commands sqlthread] eq ""
|
||||
|| [info commands sqlite3_table_column_metadata] eq ""
|
||||
} {
|
||||
return
|
||||
}
|
||||
|
||||
# Use shared-cache mode for this test.
|
||||
#
|
||||
db close
|
||||
set ::enable_shared_cache [sqlite3_enable_shared_cache]
|
||||
sqlite3_enable_shared_cache 1
|
||||
|
||||
# Create a table in database test.db
|
||||
#
|
||||
sqlite3 db test.db
|
||||
do_test thread004-1.1 {
|
||||
execsql { CREATE TABLE t1(a, b, c) }
|
||||
} {}
|
||||
|
||||
do_test thread004-1.2 {
|
||||
|
||||
set ThreadOne {
|
||||
set iStart [clock_seconds]
|
||||
while {[clock_seconds]<$iStart+20} {
|
||||
set ::DB [sqlite3_open test.db]
|
||||
sqlite3_close $::DB
|
||||
}
|
||||
}
|
||||
set ThreadTwo {
|
||||
set ::DB [sqlite3_open test.db]
|
||||
set iStart [clock_seconds]
|
||||
set nErr 0
|
||||
while {[clock_seconds] <$iStart+20} {
|
||||
incr nErr [catch {sqlite3_table_column_metadata $::DB main t1 a}]
|
||||
}
|
||||
sqlite3_close $::DB
|
||||
set nErr
|
||||
}
|
||||
|
||||
# Run two threads. The first thread opens and closes database test.db
|
||||
# repeatedly. Each time this happens, the in-memory schema used by
|
||||
# all connections to test.db is discarded.
|
||||
#
|
||||
# The second thread calls sqlite3_table_column_metadata() over and
|
||||
# over again. Each time it is called, the database schema is loaded
|
||||
# if it is not already in memory. At one point this was crashing.
|
||||
#
|
||||
unset -nocomplain finished
|
||||
thread_spawn finished(1) $thread_procs $ThreadOne
|
||||
thread_spawn finished(2) $thread_procs $ThreadTwo
|
||||
|
||||
foreach t {1 2} {
|
||||
if {![info exists finished($t)]} { vwait finished($t) }
|
||||
}
|
||||
|
||||
set finished(2)
|
||||
} {0}
|
||||
sqlite3_enable_shared_cache $::enable_shared_cache
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user