Calling `first(some_set)` gets me "ArgumentError: collection must be non-empty", even though I checked the Set for emptiness immediately before

Looks liks a data race to me. You load your data into a shared graph, push nodes from that graph onto a (thread local) working stack but you don’t make sure that only one reference to any given node exists in all working stacks. So at some point, some thread is preempted and another thread manipulates the object/Set the first thread required exclusive access to.

If you remove the Threads.@threads, it should work as designed.

2 Likes