Add a --enable-threading configure option, and only use the (slower) __sync_add_and_fetch()/__sync_sub_and_fetch() function when it is specified.

This commit is contained in:
Eric Haszlakiewicz
2017-09-03 23:37:12 -04:00
parent 8777c9477a
commit 2d1da5ab13
3 changed files with 41 additions and 8 deletions

View File

@@ -45,7 +45,7 @@ $ sh autogen.sh
followed by
```sh
$ ./configure
$ ./configure # --enable-threading
$ make
$ make install
```
@@ -56,6 +56,25 @@ To build and run the test programs:
$ make check
```
Building with partial threading support
----------------------------------------
Although json-c does not support fully multi-threaded access to
object trees, it has some code to help make use in threaded programs
a bit safer. Currently, this is limited to using atomic operations for
json_object_get() and json_object_put().
Since this may have a performance impact, of at least 3x slower
according to https://stackoverflow.com/a/11609063, it is disabled by
default. You may turn it on by adjusting your configure command with:
--enable-threading
Separately, the default hash function used for object field keys,
lh_char_hash, uses a compare-and-swap operation to ensure the randomly
seed is only generated once. Because this is a one-time operation, it
is always compiled in when the compare-and-swap operation is available.
Linking to `libjson-c`
----------------------