Skip to content
Axel Kramer edited this page Aug 17, 2024 · 9 revisions

The EvalEngine class in Symja is responsible for the evaluation of expressions.

Thread Safety in EvalEngine

The EvalEngine class (or classes which delegate to EvalEngine) in Symja is not thread-safe. This means that it cannot be used concurrently by multiple threads without external synchronization. Here are the reasons why EvalEngine is not thread-safe:

Shared Mutable State

EvalEngine maintains a mutable state that is shared among all threads. This includes variables, rules, and other settings. If multiple threads modify this state concurrently, it can lead to inconsistent and unpredictable results. This is a classic problem in concurrent programming known as a race condition.

Lack of Synchronization

EvalEngine does not use any synchronization mechanisms (like synchronized blocks or Lock objects) to control access to its internal state. This means that multiple threads can access and modify the state simultaneously, leading to data races and other concurrency issues.

Thread-Local Storage

EvalEngine uses thread-local storage for some of its data, which means that each thread has its own copy of this data. While this can help to avoid some concurrency issues, it also means that changes made by one thread are not visible to others. This can lead to inconsistencies if threads need to coordinate their actions or share results.

Non-Atomic Operations

Some operations in EvalEngine are not atomic, meaning they involve multiple steps that should be completed as a single operation. If another thread interrupts these operations, it can leave the EvalEngine in an inconsistent state.

In conclusion, while EvalEngine is a powerful tool for symbolic computation, it is not designed to be used in a multithreaded environment without additional measures to ensure thread safety. If you need to use EvalEngine in a multi-threaded application, you should ensure that access to the engine is properly synchronized, or consider using separate EvalEngine instances for each thread.

Clone this wiki locally