https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69285

nils <nilsgcc at shkoo dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nilsgcc at shkoo dot com

--- Comment #1 from nils <nilsgcc at shkoo dot com> ---
This program has an assertion failure that I believe is due to the thread
safety issues caused by this bug:

#include <parallel/algorithm>
#include <ctype.h>
#include <assert.h>
#include <random>

constexpr size_t k_element_count = 32ULL * 1024 * 1024;
constexpr size_t k_chunks = 1024;

size_t* elements = nullptr;

void do_fill() {
  if (!elements) {
    elements = new size_t[k_element_count];
  }

  std::random_device rand_dev;
  std::mt19937_64 rand_source(rand_dev());

  for (size_t idx = 0; idx != k_element_count; ++idx) {
    elements[idx] = rand_source();
  }
}

bool compare(const size_t& left, const size_t& right) {
  size_t left_val = left;
  size_t right_val = right;
  __sync_synchronize();
  size_t left_val2 = left;
  size_t right_val2 = right;

  assert(left_val == left_val2);
  assert(right_val == right_val2);

  return left_val < right_val2;
}

int main() {
  omp_set_nested(1);
  for (;;) {
    printf("Filling\n");
    do_fill();
    printf("Sorting\n");
    __gnu_parallel::sort(elements, elements + k_element_count, compare,
                         __gnu_parallel::quicksort_tag());
  }
}

I'm using:

gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 
Target: x86_64-linux-gnu

g++ -o example-case example-case.cpp -fopenmp --std=c++11

Reply via email to