Loading message with Pthreads I want to print a nice loading message with these three fading dots, while the main thread does some heavy IO stuff. This is why I implemented this:

#include &lt;stdio.h&gt;
#include &lt;pthread.h&gt;
#include &lt;unistd.h&gt;
#include &lt;stdbool.h&gt;

static bool            loadingStop;
static pthread_mutex_t loadingMutex;

void *loadingDots(void *message);

int main() {
  loadingStop = false;

  // MUTEX
  pthread_mutex_init(&amp;loadingMutex, NULL);

  // ATTRIBUTE
  pthread_attr_t attr;
  pthread_attr_init(&amp;attr);
  pthread_attr_setdetachstate(&amp;attr, PTHREAD_CREATE_JOINABLE);

  // THREAD
  pthread_t loadingThread;
  pthread_create(&amp;loadingThread, &amp;attr, loadingDots, (void *)"Loading (main, does something long)");

  pthread_attr_destroy(&amp;attr);

  // SOMETHING TIME CONSUMING 
  usleep(8000000);

  // PLEASE 'LoadingDots' TO STOP
  pthread_mutex_lock(&amp;loadingMutex);
  loadingStop = true;
  pthread_mutex_unlock(&amp;loadingMutex);

  // WAIT FOR IT TO FINISH
  pthread_join(loadingThread, NULL);
  pthread_mutex_destroy(&amp;loadingMutex);

  printf("This is printed after 'LoadingDots' savely quit.\n");

  return 0;
}

void *loadingDots(void *message)
{
  int c = 0;

  while (1) {
    switch (c) {
    case 0:
      printf("\r%s   \r%s", (char *)message, (char*)message);
      break;
    default:
      putchar('.');
      break;
    }

    fflush(stdout);
    usleep(1000000);

    c = (c+1) % 4;

    pthread_mutex_lock(&amp;loadingMutex);
    if (loadingStop) { break; };
    pthread_mutex_unlock(&amp;loadingMutex);
  }

  putchar('\n');
  pthread_exit(NULL);
}
Mostly minor stuff


Good use of fflush(stdout); to insure output.  Something often missed.
Minor: int main() { is not explicitly allowed per the standard.  Better to use int main(void) {
Minor: Naked physical quantity.  Values like height, weight, time, should have units made clear  feet vs meter $327.6 million mistake

// usleep(8000000);
#define SOME_us_TIME_CONSUMPTION (8000000 /* us */)
usleep(SOME_us_TIME_CONSUMPTION);

Minor: Avoid printf() when fputs() will do.  Avoid % issue.. BTW did you mean "safely" vs "savely"?

// printf("This is printed after 'LoadingDots' savely quit.\n");
fputs("This is printed after 'LoadingDots' savely quit.\n", stdout);
// or 
puts("This is printed after 'LoadingDots' savely quit.");

Long lines: Respect the width for the target audience - in this case code review.

// pthread_create(&amp;loadingThread, &amp;attr, loadingDots, (void *)"Loading (main, does something long)");

vs.

pthread_create(&amp;loadingThread, &amp;attr, loadingDots, 
    (void *)"Loading (main, does something long)");

Consider auto format.  The space between bool            loadingStop will likely shrink with auto formatting.  Insure code is presentable even after auto formatting.

// looks OK
static bool loadingStop;
static pthread_mutex_t loadingMutex;

Minor: Not a fan of {} one liners

// if (loadingStop) { break; };
if (loadingStop) { 
  break;
};