Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operations that change non-concurrent collections must have exclusive access at DynamicExpresso.Interpreter.SetIdentifier(Identifier identifier) #288

Open
Igor0894 opened this issue Jun 8, 2023 · 5 comments

Comments

@Igor0894
Copy link

Igor0894 commented Jun 8, 2023

Hello!
Sometimes I have a problem with non thread safe Dictionary (but I Interpreter.SetVariable in one thread):

System.InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary2.set_Item(TKey key, TValue value)
at DynamicExpresso.Interpreter.SetIdentifier(Identifier identifier)

I see that _identifiers in ParserSettings typeof Dictionary, but I dont know why I need concurent dict If i use in one thread..

Help me please!

@metoule
Copy link
Contributor

metoule commented Jun 8, 2023

Do you have an example of code that can reproduce the issue?

@Igor0894
Copy link
Author

Igor0894 commented Jun 8, 2023

Do you have an example of code that can reproduce the issue?

Do you have an example of code that can reproduce the issue?

Code have to many dependences.
Probably now I think it causes in Parralel.For loop...
May be change _identifiers type Dictionary to ConcurrentDictionary for thread safe changes?

@holdenmai
Copy link
Contributor

holdenmai commented Jun 8, 2023 via email

@davideicardi
Copy link
Member

DynamicExpresso requires to have the Interpreter class modified in an initialization phase. See https://github.com/AmikoRD/respiro-be-orders/deployments

If you call SetIdentifier only on one thread, but in the meantime other threads access it you could have problems.

You should first create the Interpreter class with all identifiers, then you can access it (calling only Parse or Eval functions) from multiple threads without problems.

@Igor0894
Copy link
Author

Igor0894 commented Jun 8, 2023

Does your external code have a single interpreter instance being called by
multiple threads?

On Thu, Jun 8, 2023, 10:49 AM Igor0894 @.***> wrote:

Do you have an example of code that can reproduce the issue?

Do you have an example of code that can reproduce the issue?

Code have to many dependences.
Probably now I think it causes in Parralel.For loop...
May be change _identifiers type Dictionary to ConcurrentDictionary for
thread safe changes?


Reply to this email directly, view it on GitHub
#288 (comment),
or unsubscribe
https://github.com/notifications/unsubscribe-auth/A2QVXQNB7JDR6Y3L5MPS3MLXKHX6ZANCNFSM6AAAAAAY7IVZ2A
.
You are receiving this because you are subscribed to this thread.Message
ID: @.***>

Yes

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

No branches or pull requests

4 participants