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. linux服务器下添加字体

    版权声明:本文为楼主原创文章,未经楼主允许不得转载,如要转载请注明来源. 引言:这两天在开发一个动态生成海报的东西(图片拼接,图片水印),开发在windows下没有问题,图片和文字都能正常的生成出来. ...

  2. javascript笔记:流程控制语句

    一.条件语句 1.if语句 if 语句即条件判断语句,一共有三种格式: (1)if (条件表达式) 语句: var box = 100; if (box >50) { alert('box大于5 ...

  3. java se the operation is not applicable to the current selection

    当新建某的类时,需要自动构建 set get方法时. 我们一般 会直接让Myeclipse自动生动.偶尔 .他会犯2. the operation is not applicable to the c ...

  4. Ms sql将首字母大写

    --辅助表 create table a ( a int ) declare @b int begin insert into a values(@b) end; go --表数据 ),id int) ...

  5. C++温习

    string abc; cin >> abc; cin把 空格,制表符,换行符作为终止符,用于提取一个词.如果在abc串中输入的内容是有空格的,流中的内容会被打乱? getline (ci ...

  6. Centos 6 之samba 搭建

    学习linux从实践做起. 实验环境:vmware,cenots 6,xshell 注意:使用vmware 时,网络连接设置成桥接,和宿主机位于同一个网段. 实验需求:模拟实际公司文件服务器. 新建S ...

  7. python生成中文验证码,带旋转,带干扰噪音线段

    # -*- coding: utf-8 -*- """ Created on Sun Oct 4 15:57:46 2015 @author: keithguofan & ...

  8. Windows的拖放操作使用方法

    Windows的拖放操作使用方法

  9. (转)SpyGlass工具介绍

    Spyglass工具有五大模块: lint,  CDC(多时钟域检查), LP(低功耗),Constraint(约束),DFT(可测试性). 一,在RTL层面上预估芯片性能,从而引导设计人员开发出更加 ...

  10. swift 批量 取出中间文本

    func stringmid_pl (wholestring:String,front:String,behind:String,inout return_string:String,getheroi ...