-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added "synchronized" keyword to these methods to avoid Concurrency mo…
…dify data: - EvalEngine#popOptionsStack - EvalEngine#peekOptionsStack - EvalEngine#pushOptionsStack - EvalEngine#stackBegin - EvalEngine#stackPop - Context#computeIfAbsent - Symbol#evalDownRule see ConcurrencyTest.java
- Loading branch information
Showing
4 changed files
with
51 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...d_library/matheclipse-core/src/test/java/org/matheclipse/core/system/ConcurrencyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.matheclipse.core.system; | ||
|
||
import org.junit.Test; | ||
import org.matheclipse.core.eval.ExprEvaluator; | ||
import org.matheclipse.core.interfaces.IExpr; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.*; | ||
|
||
public class ConcurrencyTest { | ||
|
||
@Test | ||
public void test001() throws InterruptedException, ExecutionException { | ||
|
||
String str = "SinDegree(x_):=Sin(x*Pi/180)"; | ||
|
||
ExprEvaluator exprEvaluator = new ExprEvaluator(); | ||
|
||
ExecutorService threadPool = Executors.newFixedThreadPool(4); | ||
List<Callable<IExpr>> tasks = new ArrayList<>(); | ||
for (int i = 0; i < 20; i++) { | ||
tasks.add(() -> { | ||
exprEvaluator.eval(str); | ||
return exprEvaluator.eval("Definition[SinDegree]"); | ||
}); | ||
tasks.add(() -> exprEvaluator.eval("Int[Sin(x) * Cos(x) , x]")); | ||
} | ||
|
||
|
||
List<Future<IExpr>> futures = threadPool.invokeAll(tasks); | ||
threadPool.shutdown(); | ||
|
||
for (Future<IExpr> future : futures) { | ||
IExpr iExpr = future.get(); | ||
//System.out.println("iExpr = " + iExpr); | ||
} | ||
|
||
} | ||
|
||
} |