Comments (9)
I think it isn't... I am having 3 Shortest requests that succeed if i call them sequentially, but fail if I call them concurrently. @RyanCarrier can you confirm/infirm that it is concurrency-safe? Maybe I am doing something wrong...
from dijkstra.
Having a look :)
from dijkstra.
If you mean call shortest while one is still processing, IE; have one graph, and calling shortest on it 3 times before the first has finished, yeah that will fail. it keeps it's state information within the graph itself, this is to not waste time when updating it, or say if an arc updates and you don't want everything to have to fully reprocess
If you mean have two graphs working at the same time, I have no idea why it wouldn't be working concurrently but I'll check incase I'm crazy...
from dijkstra.
Could pretty easily adjust to make the state held in the shortest method, but yeah then we lose state information for following runs of shortest which I think would be a pretty net negative?
Am I understanding correctly?
Would it be best to return an error if shortest is already running? Or reset it?
from dijkstra.
Oof sorry I mean, keeps state information so you can go through and check what's happening, it doesn't do partial updates.
from dijkstra.
Have set it now that it will return error if you run while it's already calculating. Let me know if I've missinterpreted, also added tests for concurrent testing of different graphs just to make sure that's not what you meant.
from dijkstra.
Update to v1.2.0 for fix
from dijkstra.
it keeps it's state information within the graph itself, this is to not waste time when updating it, or say if an arc updates and you don't want everything to have to fully reprocess
I'm unfamiliar with the innards of the dijkstra repo code, so take my thoughts with a grain of salt, but could we put a sync.RWMutex on the Graph struct so that operations updating state information in the graph acquire a write lock first before modifying. Then readers acquire a read lock to allow for multiple concurrent readers that aren't changing state information?
from dijkstra.
Yeah you could, but if you are at the point and you are doing the requesting and reading in different threads/routines, you would probably be implementing that yourself, so like; calculate, wait for result, pass result to other thread.
I don't think it makes sense to add a lock to the graph itself, more so to your use case of it as I feel like the default and normal way would be to define graph, then get the resulting path.
Could be as simple as like go ()func{resultChannel<-graph.Shortest()}()
I feel like I'm probably missing something here though, so if you have some source code I can look at and see the problem you're dealing with I might agree with you
from dijkstra.
Related Issues (17)
- some gentle feedback HOT 1
- error use graph HOT 1
- Wrong ShortestAll() paths HOT 2
- suggestion for HOT 1
- The shortest distance result problem HOT 2
- crash, any idea? HOT 2
- Is this package thread safe? HOT 1
- Path through given vertex HOT 2
- Is this concurrent safe? HOT 1
- Find paths in goroutines HOT 3
- License HOT 1
- about load balance HOT 8
- get multiple shortest paths? HOT 1
- Can not get more than 1 path with ShortestAll HOT 3
- Infinite loop detectedFrom node '1' to node '0' HOT 1
- Requesting tag HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dijkstra.