Read-only thread safety of existing implementations

17 views
Skip to first unread message

Sebastiano Vigna

unread,
Nov 11, 2020, 12:17:21 PM11/11/20
to jgrapht-dev
I have seen that there is a specific wrapper to access concurrently a Graph with read/write operations. However, I could find no information about the read-only thread safety of classes such as DefaultDirectedGraph or FastutilMapGraph. I think it would be useful to know from the class documentation whether they are thread safe for read-only operations, or not. The succinct implementations I'm providing are thread-safe, whereas the adapters for WebGraph graphs provide a lightweight copy mechanism

Do you think it is useful to give this kind of information to the user?

Ciao,

seba

John Sichi

unread,
Nov 11, 2020, 11:39:22 PM11/11/20
to jgrapht-dev
For the default graph implementations, we resolved this one in:

https://github.com/jgrapht/jgrapht/issues/520

so at this point we can declare them as safe for concurrent reads in the absence of concurrent writes.  I'll let Dimitrios answer regarding the Fastutil-based implementations.

We don't want to make any guarantees on the Graph interface itself, so we should add a note on every implementation class (plus the builders), as well as in the user guide.

Sebastiano Vigna

unread,
Nov 12, 2020, 7:59:36 AM11/12/20
to jgrapht-dev
I agree—I definitely would not add something like that to an interface (my adapters wouldn't comply!). But if two years ago you made it thread safe it is important that this is documented.

We are indeed using JGraphT in a EU project and we were wondering about thread safety. Knowing about the fastutil-based implementations would be even more useful. One would also expect the sparse implementations, being immutable, to be thread safe.

seba

Dimitrios Michail

unread,
Nov 12, 2020, 8:01:56 AM11/12/20
to John Sichi, jgrapht-dev
I would make a wild guess and claim that the fastutil versions also behave in a similar way as our default implementation. 
They mostly just swap the underlying hash table implementations. They do not introduce any more laziness.

Our sparse graphs are also thread-safe for read-only operations.

No idea about the guava adapters.

We should probably document this in the graph implementations.

Best, 
Dimitrios



--
You received this message because you are subscribed to the Google Groups "jgrapht-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jgrapht-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jgrapht-dev/40556557-8453-4735-b451-649826194aadn%40googlegroups.com.
Message has been deleted

John Sichi

unread,
Nov 21, 2020, 7:45:14 AM11/21/20
to jgrapht-dev
I've created a PR here.  https://github.com/jgrapht/jgrapht/pull/1005
Reply all
Reply to author
Forward
0 new messages