Commit c029a582 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix deadlock in random graph generation

Fix possible deadlock condition in random graph generation with
no_parallel and/or no_self_loops.
parent ace9d758
......@@ -521,8 +521,21 @@ struct gen_random_graph
uniform_int<size_t> source_sample(0, i-1);
// We need to check if all previous sources are not all equal to
// the first one. In that case, we should just discard this one
// and keep going.
int j;
for (j = i-1; j >= 0; --j)
if (!(sources[j] == source))
if (j < 0)
continue; // just try again
size_t s_index;
uniform_int<size_t> source_sample(0, j);
// keep trying: we don't want the same source again, and no
// sources with zero out-degree (which can happen when the graph
// is undirected, when they're orphaned after a removed edge)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment