Thread sync using conditional variables
Could be simplified

For what you are doing, using a mutex and a condition variable is more complex than necessary.  You could just use a semaphore or signal instead.  A mutex should guard some shared variable or state, but your code doesn't have any.  Instead, you are using the mutex + condition variable simply to wake up another thread.

As far as your implementation goes, I have the following comments:


A loop containing pthread_cond_wait() should always check a predicate variable to guard against spurious wakeups.  This is in the documentation for pthread_cond_wait().  So for example:

pthread_mutex_lock(&amp;count_mutex);
while (count == initialCount) {
    pthread_cond_wait(&amp;count_threshold_cv, &amp;count_mutex);
}
// Do something here...
pthread_mutex_unlock(&amp;count_mutex);

The loop doing the work should lock the mutex for as short a time as possible.  You only need to hold the mutex when you want to access shared variables.  So for example:

for (;;) {
    // Do this long work outside of the mutex
    int countnow = getDirFileCount();

    if (countnow &gt; initialCount) {
        // Only lock the mutex when you need to actually need to access
        // shared state (in this case the variable "count").
        pthread_mutex_lock(&amp;count_mutex);
        count = countnow;
        pthread_cond_signal(&amp;count_threshold_cv);
        pthread_mutex_unlock(&amp;count_mutex);
        return;
    }
}