Skip to content

Commit 8972d5a

Browse files
Merge pull request #4 from SirLynix/align-cacheline
Avoids false sharing between _top and _bottom
2 parents a455088 + 88336da commit 8972d5a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

wsq.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <vector>
55
#include <optional>
66
#include <cassert>
7+
#include <new>
78

89
/**
910
@class: WorkStealingQueue
@@ -61,8 +62,14 @@ class WorkStealingQueue {
6162

6263
};
6364

64-
std::atomic<int64_t> _top;
65-
std::atomic<int64_t> _bottom;
65+
// avoids false sharing between _top and _bottom
66+
#ifdef __cpp_lib_hardware_interference_size
67+
alignas(std::hardware_destructive_interference_size) std::atomic<int64_t> _top;
68+
alignas(std::hardware_destructive_interference_size) std::atomic<int64_t> _bottom;
69+
#else
70+
alignas(64) std::atomic<int64_t> _top;
71+
alignas(64) std::atomic<int64_t> _bottom;
72+
#endif
6673
std::atomic<Array*> _array;
6774
std::vector<Array*> _garbage;
6875

0 commit comments

Comments
 (0)