Skip to content

Aff_transformation_3 is not thread safe in Cartesian Kernels #9558

Description

@LeoValque

Issue Details

Aff_transformation_3 is not thread-safe and may cause segmentation faults when used concurrently.

Aff_transformation_3 is not thread-safe because it derives from Handle_for_virtual, which uses a non-atomic reference counter. Sharing an Aff_transformation_3 instance across threads can invalidate the counter, leading to premature deallocation and, ultimately, a segmentation fault.

Source Code

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Aff_transformation_3.h>

#include <tbb/tbb.h>

#include <vector>
#include <random>
#include <chrono>
#include <iostream>

using K = CGAL::Exact_predicates_inexact_constructions_kernel;
using P = K::Point_3;
using V = K::Vector_3;
using Tr = CGAL::Aff_transformation_3<K>;

int main()
{
  constexpr std::size_t N = 1000000;
  Tr tr(CGAL::Translation(), V(1,1,1));

  std::vector<P> vec(N, P(0,0,0));
  auto call = [&](std::size_t i){
    Tr cp = tr; // The copy is necessary to touch the counter of handle_for_virtual
    vec[i] = cp(vec[i]);
  };
  tbb::parallel_for(std::size_t(0), N, call);
}

Environment

  • Operating system (Windows/Mac/Linux, 32/64 bits): Linux
  • Compiler: GCC
  • Release or debug mode:Both
  • Specific flags used (if any):
  • CGAL version: 6.2
  • Boost version:
  • Other libraries versions if used (Eigen, TBB, etc.):

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions