why is boost lockfree freelist size is limited to a maximum of 65535 objects?

妖精的绣舞 提交于 2019-12-12 11:14:35

问题


Why is the boost lockfree size is fixed to 65535 objects?

typedef boost::lockfree::queue<int, boost::lockfree::fixed_size<true>> MyQueue;
MyQueue queue(1024*100);

The above code throws exception.

the reasoning i find in the code is that array-based freelists only support a 16bit address space.

what is the reason for this? i am using it on 64bit linux machine. then why limit the addressing to 2**16 items? does the queue use a 'short int' for indexing? does atomic instructions only work for 16bit word size?

what should i do to have a fixed sized queue with more capacity than this?


回答1:


Boost implementation of lockfree list has to fight the ABA problem. A common workaround is to add extra tag bits to the quantity being considered. Furthermore, Boost has to run on a 32-bit architecture, this means only 32-bit values can be manipulated atomically.

And if we split 32-bit value we can store 16-bit pointers and 16-bit tag. Unsigned 16-bit values are limited to 65535 different values.



来源:https://stackoverflow.com/questions/18103259/why-is-boost-lockfree-freelist-size-is-limited-to-a-maximum-of-65535-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!