Skip to content

Commit

Permalink
Tweak the shared ticket lock test
Browse files Browse the repository at this point in the history
  • Loading branch information
ademakov committed May 17, 2019
1 parent f06b624 commit 8815b17
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tests/shared-lock-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

#include <iostream>

static constexpr std::size_t test_count = 20 * 1000;
static constexpr std::size_t test_count = 10 * 1000 * 1000;

static constexpr std::size_t table_size = 8;

static constexpr std::size_t thread_num = 10;
static constexpr std::size_t thread_num = 8;
static_assert(thread_num < 16, "for testing purposes shared_ticket_lock is intentionally restricted to at most 15 threads.");

struct entry
Expand All @@ -32,7 +32,7 @@ thread_routine(std::size_t thread_idx)
table_lock.unlock_shared();

table_lock.lock();
if ((i % 1000) == 0)
if ((i % 1000000) == 0)
std::cout << "thread #" << thread_idx << " " << i << "\n";
for (std::size_t j = 0; j < table_size; j++)
table[j].value++;
Expand All @@ -43,6 +43,12 @@ thread_routine(std::size_t thread_idx)
int
main()
{
std::size_t hw_threads = std::thread::hardware_concurrency();
if (thread_num > hw_threads) {
std::cout << "WARNING: the test runs extremely slow if the number of CPU cores is below " << thread_num
<< " while your machine appears to have just " << hw_threads << ".\n";
}

evenk::thread thread_array[thread_num];
for (std::size_t i = 0; i < thread_num; i++)
thread_array[i] = evenk::thread(thread_routine, i);
Expand Down

0 comments on commit 8815b17

Please sign in to comment.