Skip to content

Instantly share code, notes, and snippets.

@janderit
Created September 18, 2012 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janderit/3742046 to your computer and use it in GitHub Desktop.
Save janderit/3742046 to your computer and use it in GitHub Desktop.
Patch fixing concurrency bug in fastJSON 2.0.5
diff --git a/fastJSON/JSON.cs b/fastJSON/JSON.cs
index d2f651e..0915fc1 100644
--- a/fastJSON/JSON.cs
+++ b/fastJSON/JSON.cs
@@ -64,7 +64,17 @@ namespace fastJSON
public sealed class JSON
{
- public readonly static JSON Instance = new JSON();
+ [ThreadStatic]
+ private static JSON _instance;
+
+ public static JSON Instance
+ {
+ get
+ {
+ if (_instance == null) _instance = new JSON();
+ return _instance;
+ }
+ }
private JSON()
{
@janderit
Copy link
Author

If someone wants to use this, please also consider making JSON.Parameters a thread safe static, See my fastJSON fork on github for an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment