读锁和写锁 [英] Read Locks and Write Locks

查看:107
本文介绍了读锁和写锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定读写锁,只需要有人检查一下有关读写锁的事实是否正确.

I am a little unsure about read and write locks and just need someone to check if these facts about read/write locks are correct.

这通常是指数据库.

读取锁:

  1. 多个线程可以同时获取多个读锁.
  2. 当线程在行/表上具有读取锁时,没有线程可以更新/插入/删除该表中的数据.(即使试图写数据的线程不需要写锁定.)
  3. 行/表不能同时具有读和写锁定.

写锁:

  1. 当行/表具有写锁时,如果另一个线程/线程中实现了读锁,则不能被其他线程读取,但是如果没有实现读锁(例如,简单的Select查询),则其他线程可以读取它/li>
  1. When a row/table has a write lock, it cannot be read by another thread if they have a read lock implemented in them but can be read by other threads if no read lock is implemented (i.e simple Select query)

感谢您的澄清.我无法在互联网上找到对这些陈述的直接断言.

Thanks for the clarification. I cant find direct assertions to these statements on the internets.

推荐答案

数据库管理理论中,锁定用于实现多个数据库用户之间的隔离.这是缩写ACID(原子性,一致性,隔离性,耐久性)中的"I".TX(事务)将锁应用于数据,这可能会阻止其他TX在TX的生存期内访问同一数据.

In database management theory, locking is used to implement isolation among multiple database users. This is the "I" in the acronym ACID (Atomicity, Consistency, Isolation, Durability). Locks are applied by a TX (transaction) to data, which may block other TXs from accessing the same data during the TX's life.

简单锁定:可以请求两种主要类型的锁定:

Simple Locking: Two main types of locks can be requested:

  • 共享锁:读取锁,即任何其他TX都可以读取但不能写入
  • 排他锁:写入锁,即其他TX都无法读取或写入
  • Shared lock: Read lock i.e. Any other TX can read but not write
  • Exclusive lock: Write lock i.e. No other TX can read or write

多重锁定: 两相锁定(2PL)是一种可确保串行化的并发控制方法.

Multiple Locking: Two Phase Locking (2PL) is a concurrency control method that guarantees serializability.

  • 增长/扩展/第一阶段:获取锁,并且不释放锁.
  • 收缩/收缩/第二阶段:释放了锁定,没有获得任何锁定.
  • A Growing/Expanding/First Phase: locks are acquired and no locks are released.
  • A Shrinking/Contracting/Second Phase: locks are released and no locks are acquired.

这篇关于读锁和写锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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