Considering using json-c, is it thread safe?

241 views
Skip to first unread message

Paul Powers

unread,
Mar 22, 2021, 4:18:34 PM3/22/21
to json-c
Hello,
I'm considering using json-c in a multi-threaded application.
Is json-c thread safe if doing cmake3 with ENABLE_THREADING?
If not, do you have any suggestions and which functions need to be protected?
Thanks in advance - Paul

Eric Hawicz

unread,
Mar 23, 2021, 2:20:12 PM3/23/21
to jso...@googlegroups.com
It should be perfectly fine to use as long as you're working on independent trees of json_object's.  Once you have multiple threads accessing the same or overlapping trees things become more iffy, and I would avoid any multi-threaded mutations or serializations.
Though there has been some effort to make reference counts work more reliably with multiple threads, that's the extent of the support.  There are no locks, memory barriers, etc... so if you really _had_ to work with json_object's across threads you'd need to handle that yourself, somehow.

Eric

Paul Powers

unread,
Mar 23, 2021, 11:28:37 PM3/23/21
to json-c
Much thanks Eric !!!
Reply all
Reply to author
Forward
0 new messages