http://www.drdobbs.com/lock-free-data-structures-with-hazard-po/184401890

memory deallocation  lock-free

session.h

/*
* WT_HAZARD --
* A hazard pointer.
*/
struct __wt_hazard {
WT_PAGE *page; /* Page address */
#ifdef HAVE_DIAGNOSTIC
const char *file; /* File/line where hazard acquired */
int line;
#endif
}; struct WT_COMPILER_TYPE_ALIGN(WT_CACHE_LINE_ALIGNMENT) __wt_session_impl {
// 略...
/*
* Hazard pointers.
*
* Use the non-NULL state of the hazard field to know if the session has
* previously been initialized.
*/
#define WT_SESSION_FIRST_USE(s) \
((s)->hazard == NULL) /* The number of hazard pointers grows dynamically. */
#define WT_HAZARD_INCR 10
uint32_t hazard_size; /* Allocated slots in hazard array. */
uint32_t nhazard; /* Count of active hazard pointers */
WT_HAZARD *hazard; /* Hazard pointer array */
};

support/hazard.c

__wt_hazard_set()

/__wt_hazard_clear()

btree.i

在__wt_page_hazard_check前, cas保证WT_REF为 WT_REF_LOCKED(btmem.h, struct __wt_ref)

__wt_page_hazard_check(WT_SESSION_IMPL *session, WT_PAGE *page)
{
WT_CONNECTION_IMPL *conn;
WT_HAZARD *hp;
WT_SESSION_IMPL *s;
uint32_t i, hazard_size, session_cnt; conn = S2C(session); /*
* No lock is required because the session array is fixed size, but it
* may contain inactive entries. We must review any active session
* that might contain a hazard pointer, so insert a barrier before
* reading the active session count. That way, no matter what sessions
* come or go, we'll check the slots for all of the sessions that could
* have been active when we started our check.
*/
WT_ORDERED_READ(session_cnt, conn->session_cnt);
for (s = conn->sessions, i = ; i < session_cnt; ++s, ++i) {
if (!s->active)
continue;
WT_ORDERED_READ(hazard_size, s->hazard_size);
for (hp = s->hazard; hp < s->hazard + hazard_size; ++hp)
if (hp->page == page)
return (hp);
}
return (NULL);
}

wiredtiger - hazard pointers的更多相关文章

  1. 关于Hazard Pointers的话题

    关于Hazard Pointers的话题, 起源于这个文章: 实现无锁的栈与队列(4) http://www.cnblogs.com/catch/p/3176636.html 其实他的系列文章(3)之 ...

  2. 风险指针(Hazard Pointer) 内存空间共享模型

    WiredTiger是一种高性能的开源存储引擎,现已在MongoDB中作为内模式应用.WiredTiger支持行存储.列存储两种存储模式,采用LSM Tree方式进行索引记录 WiredTiger支持 ...

  3. lock free数据结构内存回收技术-hazard pointer

    lock free数据结构一般来说拥有比基于lock实现的数据结构更高的性能,但是其实现比基于lock的实现更为复杂,需要处理的难题包括预防ABA问题,内存如何重用和回收等.通常,最简单最有效的处理A ...

  4. [转载]锁无关的数据结构与Hazard指针——操纵有限的资源

    Lock-Free Data Structures with Hazard Pointers 锁无关的数据结构与Hazard指针----操纵有限的资源 By Andrei Alexandrescu a ...

  5. MongoDB新存储引擎WiredTiger实现(事务篇)

    导语:计算机硬件在飞速发展,数据规模在急速膨胀,但是数据库仍然使用是十年以前的架构体系,WiredTiger 尝试打破这一切,充分利用多核与大内存时代,开发一种真正满足未来大数据管理所需的数据库.本文 ...

  6. Leetcode 笔记 117 - Populating Next Right Pointers in Each Node II

    题目链接:Populating Next Right Pointers in Each Node II | LeetCode OJ Follow up for problem "Popula ...

  7. Leetcode 笔记 116 - Populating Next Right Pointers in Each Node

    题目链接:Populating Next Right Pointers in Each Node | LeetCode OJ Given a binary tree struct TreeLinkNo ...

  8. MongoDB 存储引擎:WiredTiger和In-Memory

    存储引擎(Storage Engine)是MongoDB的核心组件,负责管理数据如何存储在硬盘(Disk)和内存(Memory)上.从MongoDB 3.2 版本开始,MongoDB 支持多数据存储引 ...

  9. [LeetCode] Populating Next Right Pointers in Each Node II 每个节点的右向指针之二

    Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...

随机推荐

  1. sql(转自http://www.imooc.com/article/2325)

    http://www.imooc.com/article/2325

  2. sudo用户管理

    合理分配用户权限 分配方法-sudo /etc/sudoers 用户名 主机名=(运行用户名) 可运行的命令 例1 smb ALL=(ALL) /usr/sbin/useradd 例2 smb ALL ...

  3. EXT学习之——EXT下拉框默认绑定第一个值

    //默认第一个下拉框绑定值if (this.moduleCombo.store.getAt(0) != undefined) { this.moduleCombo.setValue(this.modu ...

  4. lintcode-【简单题】链表求和

    题目: 你有两个用链表代表的整数,其中每个节点包含一个数字.数字存储按照在原来整数中相反的顺序,使得第一个数字位于链表的开头.写出一个函数将两个整数相加,用链表形式返回和. 样例: 给出两个链表 3- ...

  5. 使用虚幻引擎中的C++导论(四-内存管理与垃圾回收)(终)

    使用虚幻引擎中的C++导论(四)(终) 第一,这篇是我翻译的虚幻4官网的新手编程教程,原文传送门,有的翻译不太好,但大体意思差不多,请支持我O(∩_∩)O谢谢. 第二,某些细节操作,这篇文章省略了,如 ...

  6. 多个 git ssh key 配置 Ubuntu os

    1.生成ssh key: ssh-keygen -t rsa -C “email@sss.com” 此时,在~/.ssh/文件夹下会有两个文件, id_rsa 和 id_rsa.pub.分别保存ssh ...

  7. java 动态编译

    public class Main { public static void main(String[] args) { System.out.println("Hello World!&q ...

  8. 关于php多线程的记录

    最近需要对3W台服务器进行下发脚本,如果一个一个执行,时间大约在2个小时,特别的慢,于是修改程序,采用php的多线程去分发,大概在10分钟左右完成,下面记录下这次的经验和理解: 我所理解的php的多线 ...

  9. 1-11 ICMP协议

    ICMP协议 IP不提供可靠的传输服务,也不提供端到端或点到点的确认,如果出错可以通过ICMP报告来看,它在IP模块中实现.TCP/IP协议设计了ICMP就是为了弥补IP协议的不足. 它是TCP/IP ...

  10. 1.Mybatis原理

    Mybatis是一个持久层框架,Apache底下的一个项目,它的前身是ibatis,它支持普通的SQL查询,存储过程和高级映射的优秀框架.Mybatis消除了几乎所有的JDBC代码和参数的手工设置以及 ...