在Dmitry Vyukov用C++编写的优秀的有界mpmc队列中见:http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue
他添加了一些填充变量.我认为这是为了使其与高速缓存行对齐以提高性能.
我有一些问题.
__attribute__
((aligned (64))).为什么在缓冲区指针之前填充有助于提高性能?不只是指针加载到缓存中,所以它实际上只是一个指针的大小?
static size_t const cacheline_size = 64;
typedef char cacheline_pad_t [cacheline_size];
cacheline_pad_t pad0_;
cell_t* const buffer_;
size_t const buffer_mask_;
cacheline_pad_t pad1_;
std::atomic<size_t> enqueue_pos_;
cacheline_pad_t pad2_;
std::atomic<size_t> dequeue_pos_;
cacheline_pad_t pad3_;
Run Code Online (Sandbox Code Playgroud)这个概念在gcc下是否适用于c代码?