Say there's a bug that causes a program to hang, but it's hard to reproduce. It might be worth inserting assertions in code that traverses a linked structure to check that the length is less than some (very large) maximum:
int chk_count = 0; while (p = p->next) { twiddle(p); chk_count++; ASSERT(chk_count < 1000000); // way too large }If the assertion fails, then you know that somehow the program's got a cycle in the list, or something else has gone wrong. Hopefully the assertion failure produced a core dump, and you can grovel through that to find the problem.