Skip to content

Commit

Permalink
Added Simultaneous access test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ImmutableOctet committed Jun 29, 2023
1 parent c4cca7b commit 378d2c9
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/source/atomic_bitset_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <immutableoctet/atomic_bitset/atomic_bitset.hpp>

#include <thread>

#include <cstddef>
#include <cstdint>

Expand Down Expand Up @@ -34,4 +36,60 @@ TEST_CASE("immutableoctet::atomic_bitset", "[atomic-bitset]")

REQUIRE(sum_of_bits == 98);
}

SECTION("Simultaneous access")
{
auto bitset = bitset_t {};

std::size_t n_elements = 4096 * 64; // 512

auto work = [&bitset](std::size_t n_elements, std::size_t stride, std::size_t offset={})
{
for (std::size_t index = offset; index < n_elements; index += stride)
{
bitset[index] = true;
}
};

{
auto first = std::jthread
{
work,

n_elements,

static_cast<std::size_t>(3),
static_cast<std::size_t>(0)
};

auto second = std::jthread
{
work,

n_elements,

static_cast<std::size_t>(3),
static_cast<std::size_t>(1)
};

auto third = std::jthread
{
work,

n_elements,

static_cast<std::size_t>(3),
static_cast<std::size_t>(2)
};
}

std::size_t sum_of_bits = 0;

for (const bool bit : bitset)
{
sum_of_bits += static_cast<std::size_t>(bit);
}

REQUIRE(sum_of_bits == n_elements);
}
}

0 comments on commit 378d2c9

Please sign in to comment.