mengrao / wfmpmc Goto Github PK
View Code? Open in Web Editor NEWA bounded wait-free(almost) zero-copy MPMC queue written in C++11, which can also reside in SHM for IPC
License: MIT License
A bounded wait-free(almost) zero-copy MPMC queue written in C++11, which can also reside in SHM for IPC
License: MIT License
如果队列为空,while (try read); 是一个会把cpu core吃满的操作,在实际工程中适用范围很小。
此处需要一个std::condition_variable来等待,引入condition又会有新的问题,不是使用者直接引入就能解决的,应该还是需要wait-free队列处理好这个事情。
这个函数虽然是个while,但是这么看都只运行了一次吧!?
看不懂, 理解不了...
WFMPMC.h 57行那里,init_state我遇到了一种情况:init_state 为一个2打头的随机值,然后就卡在那行
在shm_comm.h中, 函数shmmap()里面,在 ret->shmInit();语句之前,少了一个 调用T构造函数。
'''
T* ret = (T*)mmap(0, sizeof(T), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
close(fd);
if(ret == MAP_FAILED)
{
std::cerr << "mmap failed: " << strerror(errno) << std::endl;
return nullptr;
}
new(ret) T(); //这一句
ret->shmInit();
'''
会导致一个问题是,mmap的文件如果是存在的,WFMPMC对象在共享内存上没有调用构造函数,导致readidx,wirteidx 没有正确赋值
"Even worse, if a writer holding an index crashes before committing, then the corresponding reader will never succeed in reading one element even if other writer has completed a write operation. This is the reason why WFMPMC is not strict wait-free."
Well, with this behaviour it is not even lock-free as lock-freedom requires system-wide progress (some thread must make progress) even if one thread fails or blocks.
With loops like this: "while((data = getWritable(idx)) == nullptr);", it is actually blocking. Essentially, each individual slot is protected by its own lock (which allows for alternating enqueues and dequeues). Any thread that continues to enqueue/dequeue objects will eventually attempt to access all slots, including any slot that is blocked.
如果pop有阻塞,那么push就会失败,这个感觉没啥用,queue都没buf
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.