in reply to
Superficial googling suggests that cond_destroy is a Unix system-call which, per the documentation, is expected to return zero, any nonzero value indicating some kind of error. We may presume (guess...) is instead returning 6. The document unfortunately does not then go on to give a list of them. Perhaps you can chase-down the OS source code of the call-handler or otherwise find a detailed explanation of each return-code possibility, but perhaps the discussion alone in the man page will provoke some worthy ideas. The fact that the problem occurs rarely-but-consistently pretty much establishes that what you have is some kind of rare-but-possible race condition bug in your code, which is “a one-in-a-million chance, but it is executed millions of times.” Sux, but that’s always the way that such things are. You didn’t need all that extra hair, anyway . . .