I use the GEOS C API to control geometry in a parallel simulator: I need objects to stay inside a restricted area. To this end, when my object takes a step, I check to see if the line
environment boundary ( environment_manager_->get_border()
which returns const GEOSPreparedGeometry*
) intersects between its previous and current position .
The code works in parallel with several OpenMP threads. I initialized GEOS before starting modeling through
initGEOS_r(notice, log_and_exit);
context_handler_ = GEOS_init_r();
therefore, I have only one handler for all threads. When running a simulation with multiple threads, the code crashes inside env_intersect
with segfault, unless I wrap it GEOSPreparedIntersects_r
in a critical section.
bool SpaceManager::env_intersect(const GEOSGeometry * line) const
{
bool intersect;
intersect = GEOSPreparedIntersects_r(
context_handler_, environment_manager_->get_border(), line);
return intersect;
}
- , ? GEOS, - OpenMP? , environment_manager_
unique_ptr
? ?
segfault :
Thread 19 "python" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffd63da700 (LWP 4374)]
0x00007ffff78816b2 in tcache_get () from /usr/lib/libc.so.6
(gdb) bt
#0 0x00007ffff78816b2 in tcache_get () at /usr/lib/libc.so.6
#1 0x00007ffff5dbf0a9 in operator new(unsigned long) (sz=sz@entry=32)
at /build/gcc-multilib/src/gcc/libstdc++-v3/libsupc++/new_op.cc:50
#2 0x00007fffc8468273 in geos::geom::LineString::computeEnvelopeInternal() const (this=0x555555f10170) at LineString.cpp:278
#3 0x00007fffc845b95f in geos::geom::Geometry::getEnvelopeInternal() const (this=0x555555f10180) at Geometry.cpp:276
#4 0x00007fffc84612ad in geos::geom::GeometryCollection::computeEnvelopeInternal() const (this=0x555555f15980) at GeometryCollection.cpp:257
#5 0x00007fffc845b95f in geos::geom::Geometry::getEnvelopeInternal() const (this=0x555555f15998) at Geometry.cpp:276
#6 0x00007ffff53cea66 in geos::geom::prep::BasicPreparedGeometry::envelopesIntersect(geos::geom::Geometry const*) const () at /usr/lib/libgeos-3.6.2.so
#7 0x00007ffff53cef82 in geos::geom::prep::PreparedLineString::intersects(geos::geom::Geometry const*) const () at /usr/lib/libgeos-3.6.2.so
#8 0x00007ffff5907380 in GEOSPreparedIntersects_r ()
at /usr/lib/libgeos_c.so.1
#9 0x00007ffff61d7938 in growth::SpaceManager::env_intersect(GEOSGeom_t const*) const (this=0x555555fb3b78, line=0x7fff7c045c20)
[EDIT], const GEOSPreparedGeometry*
OMP, segfault critical
. :
intersect = GEOSPreparedIntersects_r(
context_handler_, environment_manager_->get_border(omp_id), line);
environment_manager_->get_border(omp_id)
const GEOSPreparedGeometry*
. , , . , ...