I think I found an issue in the TopoSort() function.
As the comments say,
/* ..... * ...... If there are any other processes * in the same lock group on the queue, set their number of * beforeConstraints to -1 to indicate that they should be emitted * with their groupmates rather than considered separately. */
If the line "break;" exists, there is no chance to set beforeConstraints to -1 for other processes in the same lock group.
So, I think we need delete the line "break;" . See the patch.
I just took a look, and I found all the following versions have this line .