In SQLite, a reader/writer lock mechanism is required to control the multi-process concurrent access to a database. It is implemented using fcntl on Linux/Unix, and LockFileEx/UnlockFileEx on most Windows. But on Win95/98/ME the functions are not available. So on Win95/98/ME, SQLite uses probabilistic locking to simulate the reader/writer lock.

The idea is that using a exclusive locking pool to simulate a reader/writer lock.

  • Acquire writer lock means locking all locks in the pool
  • Acquire reader lock means locking a random lock in the pool

Writer lock is exclusive with both writer lock and reader lock. But multiple readers can access the lock at the same time, though there is some probability to conflict.

A conflict does not cause error, just makes the concurrent capacity a bit lower. The conflict probabilty depends on pool size and the concurrent process count.

In the latest SQLite, the pool size (SHARED_SIZE) is 510, according to the birthday attack formula, the 26th has more than 50% probabilistic to conflict.

Probabilistic locking in SQLite的更多相关文章

  1. Concurrent control in SQLite

    This document describes the technologies to concurrent access to a SQLite database. There are also s ...

  2. SQLite的文件锁、并发与pager---(SQLite学习手册(锁和并发控制))

    一.概述: 在SQLite中,锁和并发控制机制都是由pager_module模块负责处理的,如ACID(Atomic, Consistent, Isolated, and Durable).在含有数据 ...

  3. SQLite剖析之事务处理技术

    前言 事务处理是DBMS中最关键的技术,对SQLite也一样,它涉及到并发控制,以及故障恢复等等.在数据库中使用事务可以保证数据的统一和完整性,同时也可以提高效率.假设需要在一张表内一次插入20个人的 ...

  4. About SQLite

    About SQLite See Also... Features When to use SQLite Frequently Asked Questions Well-known Users Boo ...

  5. SQLite多线程读写实践及常见问题总结

    多线程读写 SQLite实质上是将数据写入一个文件,通常情况下,在应用的包名下面都能找到xxx.db的文件,拥有root权限的手机,可以通过adb shell,看到data/data/packagen ...

  6. SQLite入门与分析(六)---再谈SQLite的锁

    写在前面:SQLite封锁机制的实现需要底层文件系统的支持,不管是Linux,还是Windows,都提供了文件锁的机制,而这为SQLite提供了强大的支持.本节就来谈谈SQLite使用到的文件锁——主 ...

  7. Sqlite in Android

    在Android上保存本地数据有三种方式,SharedPreferences.Files和Sqlite.SharedPreferences主要是用来保存键值对形式的程序配置信息,与ini.proper ...

  8. Architecture of SQLite

    Introduction This document describes the architecture of the SQLite library. The information here is ...

  9. SQLite 线程安全和并发

    SQLite 与线程 SQLite 是线程安全的. 线程模型 SQLite 支持如下三种线程模型 单线程模型 这种模型下,所有互斥锁都被禁用,同一时间只能由一个线程访问. 多线程模型 这种模型下,一个 ...

随机推荐

  1. 条款十: 如果写了operator new就要同时写operator delete

    为什么有必要写自己的operator new和operator delete? 答案通常是:为了效率.缺省的operator new和operator delete具有非常好的通用性,它的这种灵活性也 ...

  2. Cardboard虚拟现实开发初步(二)

    Google Cardboard 虚拟现实眼镜开发初步(二) Cardboard SDK for Unity的使用 上一篇文章作为系列的开篇,主要是讲了一些虚拟现实的技术和原理,本篇就会带领大家去看一 ...

  3. 手游产品经理初探(二)从营销角度看loading界面

    近期開始写产品相关的专题,准备从细节入手去思考.总结一些不为人注意的细节地方. 今天给大家分享的是游戏里面都有的loading界面. 还是从几个在Facebook上排名靠前的Casino游戏的load ...

  4. IOS View编程指南笔记

    我们所示程序 对于一切IOS APP来说.我们看的的内容,都是UIView所呈现的. UIView如场景,UIWindow如舞台.UIView粉墨登场在UIWindow这个舞台上,使我们看到丰富多彩的 ...

  5. 使用 Code Map 理解复杂代码1 ——Visual Studio2012

    第一次知道code map是在Visual Studio Ultimate 2012自带的解说上面,当时认为十分好奇,所以查了查.结果一查就是好几天.原来Visual Studio Ultimate  ...

  6. c# WinForm的一些问题

    工作中,用WinForm写了一段程序,刚开始运行正常,后来替换为公司框架的时候,发现原来用Label拼的表格控件,里面的Text无法显示,后来发现,父控件的ForColor为Control导致,子空间 ...

  7. 【Silverlight】Bing Maps学习系列(五):绘制多边形(Polygon)图形(转)

    [Silverlight]Bing Maps学习系列(五):绘制多边形(Polygon)图形 Bing Maps Silverlight Control支持用户自定义绘制多边形(Polygon)图形, ...

  8. USACO Section 1.2PROB Miking Cows

    贪心做过去,先对每个时间的左边点进行排序,然后乱搞,当然线段树也可以做 /* ID: jusonal1 PROG: milk2 LANG: C++ */ #include <iostream&g ...

  9. bzoj 1231: [Usaco2008 Nov]mixup2 混乱的奶牛【状压dp】

    设f[i][j]为奶牛选取状态为i,最后一头选的为j,转移直接f[k][(1<<(k-1)|i]+=f[j][i] #include<iostream> #include< ...

  10. P4110 [HEOI2015]小L的白日梦

    传送门 题解 //minamoto #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef l ...