単一のデータベースのSQLiteテーブルに複数のスレッドを書き込む(WALモードが有効)C++プログラムがあります。各スレッドはSQLiteハンドルを作成し、sqlite3_open()を実行し、テーブルに書き込み(書き込みはトランザクション内にある)、sqlite3_close()を実行してSQLiteハンドルを削除します。その後、スレッドが死ぬ。SQLite:WALモードのファイルハンドルを維持する
すべてのスレッドが終了しても、SQLiteハンドルはまだ開いています。 SQLiteのハンドルが閉じられないのはなぜですか?私はここで何が欠けていますか?
私のC++プログラムはCentOS 5.5で動作しています。
ここでは、[編集] は、SQLiteのチームに連絡pthread
void threadFunction(void* pArg) {
sqlite3 *handle;
sqlite3_open("a.cm", &handle);
printf("Worker thread - Opened \n");
sleep(10);
int r = sqlite3_close(handle);
printf("Ret: %d\n", r);
printf("Worker thread - Closed \n");
}
int main() {
int i(0);
pthread_t thread1, thread2;
printf("Creating a worker thread\n");
printf("SQLite libversion: %s\n", sqlite3_libversion());
sqlite3 *handle;
sqlite3_open("a.cm", &handle);
sqlite3_exec(handle, "pragma journal_mode = WAL", NULL, NULL, NULL);
printf("Main thread - Opened \n");
pthread_create(&thread1, NULL, threadFunction, NULL);
pthread_create(&thread2, NULL, threadFunction, NULL);
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
sleep(200);
sqlite3_close(handle);
printf("Main thread - close \n");
return 0;
}