確認在 "sqlite3.c" 中,巨集 sqlite_threadsafe = 1 或者 2
# define sqlite_threadsafe 1 /* imp: r-07272-22309 */
#include "thread.h"
extern "c"
;#include #include "utility.h"
//int print(void *pparam, int argc, char ** argv, char ** szcolname)
void start()
void stop()
void svc(cthread *pthread, handle hexit)
;while (true)
wsprintfa(szsql, "select * from demotable where thread = 1");
result = sqlite3_exec(m_psqlite3, szsql, print, null, &errmsg);
printf("\n\n\n");
wsprintfa(szsql, "delete from demotable where thread = 1");
result = sqlite3_exec(m_psqlite3, szsql, null, null, &errmsg);}}
if (pthread == &m_threadwrite) ;
while (true)
wsprintfa(szsql, "insert into demotable values(%d, %d)", lthread, lcount++);
result = sqlite3_exec(m_psqlite3, szsql, null, null, &errmsg);}}
}private:
sqlite3 *m_psqlite3;
long m_lthreadcount;
cthread m_threadread;
cthread m_threadwrite;
};//
int main()
result = sqlite3_exec(psqlite, "create table if not exists demotable(thread integer, count integer)", null, null, &errmsg);
result = sqlite3_exec(psqlite, "delete from demotable", null, null, &errmsg);
demosqlite demosqlite(psqlite);
demosqlite.start();
sleep(1000 * 5);
demosqlite.stop();
sqlite3_close(psqlite);
return 0;
}
SQLite 多執行緒
sqlite支援3種執行緒模式 單執行緒 這種模式下,沒有進行互斥,多執行緒使用不安全。禁用所有的mutex鎖,併發使用時會出錯。當sqlite編譯時加了sqlite threadsafe 0引數,或者在初始化sqlite前呼叫sqlite3 config sqlite config singlet...
關於sqlite多執行緒
1 如果是sqlite open fullmutex,也就是序列化方式,則對於連線時互斥的,只有乙個連線關閉,另外乙個連線才能讀寫 2 如果是sqlite open nomutex,則是多執行緒模式,對於寫是互斥的,但是如果乙個連線持續寫,另外乙個連線是無法寫入的,只能是錯誤或者超時返回。不過乙個連...
SQLite多執行緒使用
sqlite支援3種執行緒模式 單執行緒 這種模式下,沒有進行互斥,多執行緒使用不安全。禁用所有的mutex鎖,併發使用時會出錯。當sqlite編譯時加了sqlite threadsafe 0引數,或者在初始化sqlite前呼叫sqlite3 config sqlite config singlet...