GithubHelp home page GithubHelp logo

mikewei / shm_container Goto Github PK

View Code? Open in Web Editor NEW
231.0 231.0 102.0 112 KB

A collection of shared memory containers for high performance server

C++ 98.99% C 0.78% Starlark 0.23%
cpp11 shm shm-container sysv

shm_container's People

Contributors

mikewei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shm_container's Issues

ShmQueue 应该不是线程安全的

看了下ShmQueue 应该不是线程安全的,即使在单读单写下,问题出在你用一个volatile变量在控制一块内存,C++里面volatile只保证每次取值一定是去内存那边取,但是指令乱序没有保证的,在x86架构下,可能这个代码不会跑出问题,但是在其他(arm,power)这样的架构下很容易跑出问题,所以为了安全起见,还是用c++11的atomic吧。

ShmSyncBuf<Alloc>::InitForWrite创建时参数检查BUG

原代码如下:

bool ShmSyncBuf::InitForWrite(const std::string& shm_key,
size_t buf_size_bytes) {
// .......
if (buf_size_bytes < (kOverwriteBufferSize * 2)
&& buf_size_bytes > 0x800000000UL /* 2^32 x 8B */) {
SHMC_ERR_RET("ShmSyncBuf::InitForWrite: invalid buf_size_bytes\n");
}
// .......
}

if (buf_size_bytes < (kOverwriteBufferSize * 2) && buf_size_bytes > 0x800000000UL / 2^32 x 8B /) 这里 && 做判断值应该时存在BUG的,作者想对入参buf_size_bytes做校验,应该需要用 ||

shm_hash_map 多进程问题

请教下,一个进程去写:
shmc::ShmHashMap<const char *, shmc::POSIX> hash_map_;
shmc::POSIX alloc_;
hash_map_.InitForWrite(kShmKey, kKeyNum, kNodeSize, kNodeNum);
const char *key = "testkey";
while(1){
hash_map_.Replace(key, value.c_str());
sleep(1);
}
然后另外一个进程去读,
shmc::ShmHashMap<const char *, shmc::POSIX> hash_map_;
shmc::POSIX alloc_;
hash_map_.InitForRead(kShmKey);
const char *key = "testkey";
while(1){
std::string out;
if(hash_map_.Find(key, &out)){
printf("%s\n",out.c_str());
}
sleep(1);
}

但是为啥读的那个进程一直提示
ShmHashMap::Find: key not found
哪里出了问题呢?

hash_map 获取数据问题

hash_map 每次获取数据Find接口都是对原数据的一次拷贝,是否可设计成获取源数据,让使用者操作数据。比如我存入一个结构体,想修改里面的值,需要Find接口拷贝数据到std::sting 再通过指针转换成定义的结构体修改完数据后再replace 拷贝一次数据,这样是不是太麻烦了

shmqueue init for read bug

you call InitForWrite in ShmQueue::InitForRead, i think this is a bug.

template <class Alloc>
bool ShmQueue<Alloc>::InitForRead(const std::string& shm_key) {
  if (shm_.is_initialized()) {
    SHMC_ERR_RET("ShmQueue::InitForRead: already initialized\n");
  }
  if (!shm_.InitForWrite(shm_key, sizeof(ShmHead), kNoCreate)) {
    SHMC_ERR_RET("ShmQueue::InitForRead: shm_.InitForRead(%s, %lu) fail\n",
                                         shm_key.c_str(), sizeof(ShmHead));
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.