You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One very common usage is the same expression used for evaluation in multiple thread environment with different paramter very frequently. As the expression string is same, we don't want to compile it every time. If it is in single thread envionment, we could replace the owner in the generated IL delegate:
However, as the owner replacement and evaluatation need to use an internal _myOwner to pass owner, in multiple threading environment this will fail:
//This is failed test case:[Test]publicvoidMultipleOwnerTest(){varowner=newOwner();ExpressionContextcontext=newExpressionContext(owner);vartasks=newList<Task<bool>>();vare1=context.CompileGeneric<bool>("Number % 2 = 1");for(inti=0;i<1000;++i){varlocal=i;vartcs=newTaskCompletionSource<bool>();tasks.Add(tcs.Task);Task.Run(()=>{e1.Owner=newOwner(){Number=local};tcs.SetResult(e1.Evaluate()==(local%2==1));});}Task.WaitAll(tasks.ToArray());Assert.IsTrue(tasks.All(x=>x.Result));}
One solution is to expose one overloaded method which accepts the owner:
// In Flee.InternalTypes.ExpressionpublicobjectEvaluate(objectowner){ValidateOwner(owner);return_myEvaluator(owner,_myContext,_myContext.Variables);}publicTEvaluateGeneric(objectowner){ValidateOwner(owner);return_myEvaluator(owner,_myContext,_myContext.Variables);}
I tested locally with above test case and this solution works.
The text was updated successfully, but these errors were encountered:
One very common usage is the same expression used for evaluation in multiple thread environment with different paramter very frequently. As the expression string is same, we don't want to compile it every time. If it is in single thread envionment, we could replace the owner in the generated IL delegate:
However, as the owner replacement and evaluatation need to use an internal _myOwner to pass owner, in multiple threading environment this will fail:
One solution is to expose one overloaded method which accepts the owner:
I tested locally with above test case and this solution works.
The text was updated successfully, but these errors were encountered: