Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Efficient C++ Bounded Thread-Safe FIFO Queue and LIFO Stack version 1.12

62 views
Skip to first unread message

amin...@gmail.com

unread,
Sep 6, 2017, 1:14:32 PM9/6/17
to
Hello,


Efficient C++ Bounded Thread-Safe FIFO Queue and LIFO Stack version 1.12

I have properly aligned and padded for false-sharing, here is what i have used:

#if defined(__GNUC__)
#ifndef ALIGN64
#define ALIGN64 __attribute__((aligned (64)));
#endif
#else
#ifndef ALIGN64
#define ALIGN64 __declspec(align(64))
#endif
#endif

And of course i have added the padding.

Author: Amine Moulay Ramdane

Description:

Efficient C++ Bounded Thread-Safe FIFO Queue and LIFO Stack , they are efficient and they eliminate false-sharing.

Language: GNU C++ and Visual C++ and C++Builder


You can download it from:

https://sites.google.com/site/aminer68/efficient-c-bounded-thread-safe-fifo-queue-and-lifo-stack



Thank you,
Amine Moulay Ramdane.

Mr Flibble

unread,
Sep 6, 2017, 5:29:01 PM9/6/17
to
Now you are aligning each variable to cacheline size the padding
inbetween the aligned variables is totally redundant. The correct
solution I gave you yesterday (which ensures last variable has padding
after it):

template<typename T>
struct cache_line_storage {
alignas(CACHE_LINE_SIZE) T data;
char pad[CACHE_LINE_SIZE > sizeof(T)
? CACHE_LINE_SIZE - sizeof(T)
: 1];
};

/Flibble

Chris M. Thomasson

unread,
Sep 9, 2017, 6:04:30 PM9/9/17
to
Humm... A corner case, think about when sizeof for a user provided T
happens to be equal to a cache line size, now you have a dangling char
intruding into the next cache line at an alignment boundary.

if sizeof(T) == CACHE_LINE_SIZE, then cache_line_storage<T> will have:

struct cache_line_storage
{
alignas(CACHE_LINE_SIZE) T data;
char pad[1];
};

Well, this intrudes into the next cache line because
sizeof(cache_line_storage<T>) will be greater than CACHE_LINE_SIZE.

This is a corner case, but, imho, worth pointing out. Sorry for nit
picking.

Mr Flibble

unread,
Sep 9, 2017, 7:48:22 PM9/9/17
to
It wasn't my code any way, I copied it off a Dr Dobb's article. :)

/Flibble
0 new messages