BDB concurrent access
来源:互联网 发布:mac itunes 同步铃声 编辑:程序博客网 时间:2024/06/05 11:45
This is a brief introduction of howto use BDB concurrently, and also give a sample code snippet.
Usage key points:
1. In order to support concurrentBDB access, BDB environment (DbEnv) must be used.
a) DbEnv must be open() with DB_INIT_LOCKflags.
b) In fact, DB_INIT_CDB useimplicit lock strategy for multiple read /single write access mode, that means lock subsystem is not enabled, so mutex/lock cannot be explicitly used in this mode.
c) Please refer to: http://docs.oracle.com/cd/E17076_02/html/api_reference/C/envopen.html#envopen_DB_INIT_CDB
2. mutex: mutex object is validonly within a process, i.e., mutex cannot be used cross process.
3. lock: lock object is valid forboth cross threads and cross processes.
4. BDB concurrent cannot supportwhen database is resident on a NFS.
a) Please refer to: http://www.oracle.com/technetwork/database/berkeleydb/db-faq-095848.html
Code Sample: use a mutex
int main() { /** initialize DbEnv */ DbEnv * env = new DbEnv(0); env->open("data", DB_CREATE | DB_INIT_LOCK | DB_INIT_MPOOL, 0644); /** initialize mutex object */ db_mutex_t mutex; env->mutex_alloc(DB_MUTEX_SELF_BLOCK, &mutex); /** lock mutex */ env->mutex_lock(mutex); /** unlock mutex */ env->mutex_unlock(mutex); /** release mutex */ env->mutex_free(mutex);}
Code Sample: use a lock
int main() { /** initialize DbEnv */ DbEnv * env = new DbEnv(0); env->open("data", DB_CREATE | DB_INIT_LOCK | DB_INIT_MPOOL, 0644); /** initialize lock object */ u_int32_t lockid; env->lock_id(&lockid); DbLock lock; db_lockmode_t lock_type = DB_LOCK_WRITE; char objbuf[1024]; sprintf(objbuf, "testlock"); Dbt dbt(objbuf, (u_int32_t)strlen(objbuf)); /** hold lock */ env->lock_get(lockid, 0, &dbt, lock_type, &lock); /** release lock */ env->lock_put(&lock); /** release lockid */ env->lock_id_free(lockid);}
- BDB concurrent access
- bdb
- bdb
- BDB 临时
- bdb专题
- bdb 读取
- BDB安装
- BDB 封装
- Java Thread Programming 1.7 - Concurrent Access to Objects and Variables
- concurrent
- concurrent
- concurrent
- concurrent
- 七、BDB JE与BDB Java API
- Berkeley DB(BDB)
- bdb 数据库练习
- BDB C# API初探
- 八、BDB OneToOne
- mysql常用操作
- caffe安装总结
- MAC之Qt在Xcode8上编译错误(一)
- JDBC的连接和操作
- 每日一省之————红黑树的java实现
- BDB concurrent access
- [学习笔记]MySql存储过程学习二
- Python基本数据类型的注意事项
- 简易学生管理系统(IO流、文件、)
- VNC服务
- BDB C++ API sample
- HAXM is not installed
- Android 6.0 权限管理
- SQL注入攻击以及防护