On Mon, 9 May 2016 11:53:24 -0700 (PDT), Jorge Rocha Gualtieri wrote:
> Is SpatiaLite thread-safe? Are there compile directives to enable it?
>
Hi Jorge,
SpatiaLite itself is expected to be thread-safe, but some
depending library isn't.
GEOS, PROJ.4 and LIBLWGEOM were not thread-safe in past
years, and only their most recent versions are expected
to be finally thread-safe.
please notice: your issue is actually caused by GEOS.
asking "is spatialite thread-safe ?" makes very little
technical sense if you omit to clearly specify:
- which version of libspatialite are you using
- and which version of GEOS, PROJ.4 (and may be of LWGEOM)
as a rule of the thumb, earlier versions (4.2 and 4.3)
are expected to be possibly affected by some residual
multi-threading issue (in decreasing severity).
the most recent 4.4 (when built on the top of the
latest GEOS 3.4.5 and RTTOPO) will be finally completely
thread-safe.
lt-demo2: geos_ts_c.cpp:3657: int GEOSCoordSeq_setOrdinate_r(GEOSContextHandle_t, geos::geom::CoordinateSequence*, unsigned int, unsigned int, double): Assertion `0 != cs' failed.[1] 15401 abort (core dumped) ./demo2
#0 0x00007ffff6fda04f in raise () from /usr/lib/libc.so.6#1 0x00007ffff6fdb47a in abort () from /usr/lib/libc.so.6#2 0x00007ffff6fd2ea7 in __assert_fail_base () from /usr/lib/libc.so.6#3 0x00007ffff6fd2f52 in __assert_fail () from /usr/lib/libc.so.6#4 0x00007ffff5c795d8 in GEOSCoordSeq_setOrdinate_r () from /usr/lib/libgeos_c.so.1#5 0x00007ffff737ff95 in ?? () from /usr/lib/libspatialite.so.7#6 0x00007ffff73879e4 in gaiaIsValid () from /usr/lib/libspatialite.so.7#7 0x0000000000401226 in main ()
./configure --prefix=/usr --enable-libxml2 CPPFLAGS="$CPPFLAGS -DGEOS_USE_ONLY_R_API"
when instead an earlier version of GEOS (< 3.5.0= is actually
found ./configure will stop by reporting the following error:
-------------------------------------------------------------
"libgeos_c' (>= v.3.5.0) is required but it doesn't seem to be
installed on this system. You may need to try re-running
configure with a --disable-geosreentrant parameter."
-------------------------------------------------------------
you can find a public announcement explaining all this stuff
in this previous post of mine:
https://groups.google.com/forum/#!searchin/spatialite-users/geosreentrant%7Csort:relevance/spatialite-users/OGjFsIYW5F0/Jhpp1FsPCgAJ
bye Sandro
toGeosGeometry (const void *cache, GEOSContextHandle_t handle,
// ...
printf("[%d]\n", __LINE__); //print the line num
[235]
But both 4.3.0a and 4.4.0-RC don't work with GEOS 3.5.0 with default 'configure', -DGESO_USE_ONLY_R_API is still needed, am I wrong?
config.h:/* Should be defined in order to enable GEOS_REENTRANT (fully thread-safe). */config.h:#define GEOS_REENTRANT 1
checking for geos-config... /usr/local/bin/geos-configchecking geos_c.h usability... yeschecking geos_c.h presence... yeschecking for geos_c.h... yeschecking for library containing GEOSCoveredBy... -lgeos_cchecking for library containing GEOSDelaunayTriangulation... none requiredchecking for library containing GEOSContext_setErrorMessageHandler_r... none required
cat /usr/local/bin/geos-config | grep '3.' echo 3.5.0
On Thursday, 6 October 2016 11:10:02 UTC+2, 邹鲁 wrote:But both 4.3.0a and 4.4.0-RC don't work with GEOS 3.5.0 with default 'configure', -DGESO_USE_ONLY_R_API is still needed, am I wrong?No, with 4.4.0-RC it should work.You should see the following in the config.h file after ./configure
config.h:/* Should be defined in order to enable GEOS_REENTRANT (fully thread-safe). */config.h:#define GEOS_REENTRANT 1
"GEOS_REENTRANT 1" : YES
as Sandro explained before, when GEOS_REENTRANT 1
- GESO_USE_ONLY_R_API will be used
so check what you have in your config.h file--When running ./configure, you should see
checking for geos-config... /usr/local/bin/geos-configchecking geos_c.h usability... yeschecking geos_c.h presence... yeschecking for geos_c.h... yeschecking for library containing GEOSCoveredBy... -lgeos_cchecking for library containing GEOSDelaunayTriangulation... none requiredchecking for library containing GEOSContext_setErrorMessageHandler_r... none required
look inside the '/usr/local/bin/geos-config' file
cat /usr/local/bin/geos-config | grep '3.'echo 3.5.0you should see 'echo 3.5.0'
I've checked the GEOS' web site, it's changelog of 3.5.0 suggests " - GEOS_USE_ONLY_R_API macro support (#695)" is there.
Ref: https://trac.osgeo.org/geos/browser/tags/3.5.0/NEWS
Indeed, this macro should only affects libspatialite. Now I do believe it had some impact on libspatialite, namely returning NULL for non-reentrant functions as evidented in the backtrace. But the problem is that the user ('demo2' in this case) didn't invoke any high level function. It just invoked 'gaiaIsValid()'. It's the library itself that invoked toGeosGeometry(). the internal variable 'cs' is set to NULL and get passed to GEOS, which rosed the assertion failure.
I do see some definitions like '#ifndef GEOS_USE_ONLY_R_API ... some_func() ... #else ... some_func_r()'. It's inside the 'gg_geoscvt.c'. And I have proved that the non-reentrant branch got selected. That's why I thought the macro didn't take effect.
So here is the controversy: if the macro made non-reentrant functions return NULL, why it didn't make toGeosGeometry() to select the correct functions that are reentrant?
Or maybe I should invoke something like gaiaIsValid_r() instead?
Apologies if I spelled some names inaccurately, cause I don't have access to my computer right now.
Best wishes!
--Lu