Git Product home page Git Product logo

Comments (2)

FSMaxB avatar FSMaxB commented on July 17, 2024

In general: No.

But it depends on how you use it.

There are three global variables:

  • global_ep: If parsing fails it contains a pointer to the position in the input string where it happened. It is automatically set by cJSON_Parse.
  • cJSON_Malloc and cJSON_Free: Function pointers pointing to the allocator and deallocator that is used by cJSON. They can be set with cJSON_InitHooks.

If you don't rely on these, cJSON is thread safe. You can avoid using global_ep by parsing with cJSON_ParseWithOpts, if not NULL, it will use return_parse_end instead of global_ep.

So cJSON is thread safe under these conditions:

  • Use cJSON_ParseWithOpts and pass in your own error pointer via return_parse_end
  • Either don't use cJSON_InitHooks, or only do it once at the beginning, before any thread starts using the library.

With the upcoming 2.0.0 release, cJSON will be thread safe though, because the global variables will be replaced by ones that are passed in on every function call. But I can not make any guarantees as to when 2.0.0 will be ready.

from cjson.

matze avatar matze commented on July 17, 2024

Use cJSON_ParseWithOpts and pass in your own error pointer via return_parse_end

I don't think this is correct. At the beginning global_error.json and global_error.position are reset unconditionally and in the failure case, global_error is overwritten unconditionally.

Is there a timeline for a 2.0 release?

from cjson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.