- 論壇徽章:
- 0
|
硬件平臺: Linux on vmware6
操作系統(tǒng):Trustix Linux3
SQLITE: sqlite-3.5.7
以下摘自:http://www.sqlite.org/c3ref/open.html
int sqlite3_open(
const char *filename, /* Database filename (UTF-8) */
sqlite3 **ppDb /* OUT: SQLite db handle */
);
If the filename is ":memory:", then an private
in-memory database is created for the connection. This in-memory
database will vanish when the database connection is closed. Future
version of SQLite might make use of additional special filenames
that begin with the ":" character. It is recommended that
when a database filename really does begin with
":" that you prefix the filename with a pathname like "./" to
avoid ambiguity.
我在主線程中使用
int sqlitehandle = sqlite3_open(":memory:", &pdb);
創(chuàng)建內存數據庫,并創(chuàng)建表:
int rs = sqlite3_exec(pdb, "CREATE TABLE testtbl(id int NOT NULL, name varchar(100))", 0, 0,0);
然后創(chuàng)建兩個新的線程,將pdb傳入線程中,主線程進入睡眠。
在兩個線程中,均執(zhí)行:
while(1) { int rs = sqlite3_exec(pdb, "INSERT INTO testtbl values(25,'aaaaaaaaaaaa')", 0,0,0); printf("rs = %d\n", rs); if(rs != SQLITE_OK) { printf("err rs=%d\n", rs); break; } usleep(10); }
測試結果顯示是可以兩個線程操作同一個句柄的!!!
并且在程序運行時,我用lsof命令查看該進程的句柄狀態(tài),確實沒有任何磁盤的操作!!!
但有個問題不知道是否是由于我是虛擬機引起,即該程序在執(zhí)行(約1分鐘后),兩個線程像是進入死鎖狀態(tài),再沒有任何動作,沒有退出,也沒有顯示insert失。∵@暫時不理解。
![]()
文件:sqlite-3.5.7.tar.gz
大小:2506KB
下載:
下載
本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u/870/showart_504264.html |
|