-
Notifications
You must be signed in to change notification settings - Fork 23
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
Issue with thread-safety #76
Comments
First of all, thanks for the feedback, we are happy to see the first users. |
To me, the wrap-up of the problem is: Having an internal state in a singleton is very error prone. There are already thoughts on my side, inspired by the way we moved Calculator.java "to the top-most level" in v2.5. It probably requires a considerable rework:
|
Agreed. We should remove those singletons and take a task to check classes for thread-safety. Hopefully no other issues. |
The problem as I see after checking in ArrivalBound Dispatch.computeArrivalBounds: Same switch but thread-safe: Why do we have 2 approaches? What is the difference between the 2? |
These are two different ways to compute an arrival curve bounding the arrivals of flows in Employing only the PBOO principle, the
When we can make use of PMOO,, however, the
As to why the design is inconsistent w.r.t. thread-safety, the answer is simply because the code grew organically with the understanding of this matter and thread-safety had never been in the focus. For the proposed new |
In my opinion the analysisconfig will not solve the issue as the problem is you update the references/values in a a class that has only one instance in the memory while another thread is using it. The solution is to remove singleton and create new instances with each calculation as it is done for the second example I gave. That is why I asked whether it was a must to use singleton in the first one. Singleton classes with instance variables are not thread-safe. |
Sure, the singleton will be removed (sorry if that wasn't clearly stated). Creating a new instance every time we reach this location in the code introduces unnecessary overhead, too. I think one instance per Analysis object is sufficient because the concurrent modifications of the singleton come from different analysis configurations. So I propose to embed the instance the an analysis uses into it and shield it from the other potential analysis instances. The same holds for the arrival bounds cache that I intend to merge into the v2.6-dev branch soon. |
I have some code using the DNC library where I perform analyses of multiple networks in different threads. This leads to errors in the analyses which do not appear when only one thread is used.
Some debugging lead me to
ArrivalBoundDispatch.java
and the arrivalbound classes. Singletons are used for doing the computations, and usesetServerGraph(server_graph)
andsetConfiguration(configuration)
to configure it, before callingcomputeArrivalBound
. The issue is that if there are multiple threads, you might have the case thatsetServerGraph
is executed by one thread, while another thread is still executingcomputeArrivalBound
. I validated my theory by creating a new arrivalbound instance for each computation, resulting in no errors.ArrivalBoundCache
, in its current implementation, is also not thread-safe.Hence, I suggest to modify DNC library in order to use thread-safe data structures, and thus enable parallelization of (some) computations.
The text was updated successfully, but these errors were encountered: