June 1, 2005 sem_wait can return -1 with errno == EINTR according to the latest POSIX standard. The GNU NPTL threads library actually does this. I believe this is patched now, but I'll use sem-pthread.h for now, which is my own non-optimal implementation, which never returns -1. After further testing, sem-pthread.h will go away. The bug appeared only in gdb. To illustrate the bug: make gdb gdb hello_mpi > b MPI_Send > run Then single step using: n DBG_COUNT will go negative, triggering an assert. This means that something bad happened in the producer-consumer code of send_nonblock.c Note that this happened _only_ if using Linux libthread_db and the standard Linux libpthread (with semaphore.h API) libthread_db: /lib/tls/libthread_db.so.1 The bug did not occur if I use my own sem-pthread.h, that implements sem_wait, sem_post, etc., in terms of pthread primitivies (mutex, condition). Hopefully, the fix, suggested by Peter Portante, will mean that sem-pthread.h can go away in the future.