thread004.test 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. set testdir [file dirname $argv0]
  14. source $testdir/tester.tcl
  15. if {[run_thread_tests]==0} { finish_test ; return }
  16. ifcapable !shared_cache {
  17. finish_test
  18. return
  19. }
  20. if { [info commands sqlite3_table_column_metadata] eq "" } {
  21. finish_test
  22. return
  23. }
  24. # Use shared-cache mode for this test.
  25. #
  26. db close
  27. set ::enable_shared_cache [sqlite3_enable_shared_cache]
  28. sqlite3_enable_shared_cache 1
  29. # Create a table in database test.db
  30. #
  31. sqlite3 db test.db
  32. do_test thread004-1.1 {
  33. execsql { CREATE TABLE t1(a, b, c) }
  34. } {}
  35. do_test thread004-1.2 {
  36. set ThreadOne {
  37. set iStart [clock_seconds]
  38. while {[clock_seconds]<$iStart+20} {
  39. set ::DB [sqlite3_open test.db]
  40. sqlite3_close $::DB
  41. }
  42. }
  43. set ThreadTwo {
  44. set ::DB [sqlite3_open test.db]
  45. set iStart [clock_seconds]
  46. set nErr 0
  47. while {[clock_seconds] <$iStart+20} {
  48. incr nErr [catch {sqlite3_table_column_metadata $::DB main t1 a}]
  49. }
  50. sqlite3_close $::DB
  51. set nErr
  52. }
  53. # Run two threads. The first thread opens and closes database test.db
  54. # repeatedly. Each time this happens, the in-memory schema used by
  55. # all connections to test.db is discarded.
  56. #
  57. # The second thread calls sqlite3_table_column_metadata() over and
  58. # over again. Each time it is called, the database schema is loaded
  59. # if it is not already in memory. At one point this was crashing.
  60. #
  61. unset -nocomplain finished
  62. thread_spawn finished(1) $thread_procs $ThreadOne
  63. thread_spawn finished(2) $thread_procs $ThreadTwo
  64. foreach t {1 2} {
  65. if {![info exists finished($t)]} { vwait finished($t) }
  66. }
  67. set finished(2)
  68. } {0}
  69. sqlite3_enable_shared_cache $::enable_shared_cache
  70. finish_test