Sqlite 的序列化模式 [英] Sqlite's Serialized mode

查看:23
本文介绍了Sqlite 的序列化模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此处的文档中:http://www.sqlite.org/threadsafe.html

对于序列化模式,它说:在序列化模式下,SQLite 可以被多个线程安全地使用,没有限制."

For serialized mode it says: "In serialized mode, SQLite can be safely used by multiple threads with no restriction."

我想确保我理解那里提供的保证.如果使用SQLITE_OPEN_FULLMUTEX"标志打开单个数据库连接,并且两个线程同时尝试在同一时刻调用 sqlite3_exec,Sqlite 会自动序列化调用吗?

I want to make sure I understand the guarantee presented there. If a single database connection is opened using the "SQLITE_OPEN_FULLMUTEX" flag and two threads simultaneously try to call sqlite3_exec at the exact same instant, does Sqlite automatically serialize the calls?

推荐答案

答案是肯定的.sqlite3_exec() 将在进入函数时获取互斥体,并在函数离开后释放互斥体.在任何给定时间只有一个线程可以拥有互斥锁,因此在任何给定时间只有一个线程可以执行 sqlite3_exec().如果两个线程试图同时执行 sqlite3_exec(),一个将等待另一个.

The answer is yes. sqlite3_exec() will grab a mutex when the function is entered and releases the mutext once the function is left. Only one thread can own the mutex at any given time, so only one thread can execute sqlite3_exec() at any given time. If two threads try to execute sqlite3_exec() at the same time, one will wait for the other.

这篇关于Sqlite 的序列化模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆