After some testing, it seems that Linux already does what I want automatically! You only need to link against pthreads if you use threading, not if you just want pthread mutex support.
In this test case:
#include <stdio.h>
#include <errno.h>
#include <pthread.h>
int main()
{
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
if (!(errno = pthread_mutex_lock(&mutex))) { puts("Mutex locked!"); }
else { perror("Could not lock mutex"); }
if (!(errno = pthread_mutex_lock(&mutex))) { puts("Mutex locked!"); }
else { perror("Could not lock mutex"); }
return 0;
}
When compiling this without pthreads linked, I see "Mutex locked!" twice. Which indicates that pthread_mutex_lock() is essentially a non-op. But with pthreads linked, running this application will stall after the first time "Mutex locked!" is printed.
Therefore, I can use mutexes in my library where appropriate, and don't need to require pthreads to use, and no (signifigant?) overhead where it isn't needed.