diff --git a/src/xpdev/xpbeep.c b/src/xpdev/xpbeep.c
index 7f2a429c3f8ef9b7546d50ffe359c036972e113f..70f7aa78b807330e225a0a40bd5a5a20b0029cf9 100644
--- a/src/xpdev/xpbeep.c
+++ b/src/xpdev/xpbeep.c
@@ -210,6 +210,8 @@ struct alsa_api_struct {
 struct alsa_api_struct *alsa_api=NULL;
 #endif
 
+static void init_sample(void);
+
 /********************************************************************************/
 /* Calculate and generate a sound wave pattern (thanks to Deuce!)				*/
 /********************************************************************************/
@@ -364,6 +366,7 @@ void DLLCALL sdl_fillbuf(void *userdata, Uint8 *stream, int len)
 }
 #endif
 
+pthread_once_t sample_initialized_pto = PTHREAD_ONCE_INIT;
 static BOOL
 DLLCALL xptone_open_locked(void)
 {
@@ -649,6 +652,7 @@ DLLCALL xptone_open(void)
 {
 	BOOL ret;
 #ifdef XPDEV_THREAD_SAFE
+	pthread_once(&sample_initialized_pto, init_sample);
 	pthread_mutex_lock(&handle_mutex);
 #endif
 	ret = xptone_open_locked();
@@ -1048,8 +1052,7 @@ error_return:
 	sample_thread_running=FALSE;
 }
 
-pthread_once_t sample_initialized_pto = PTHREAD_ONCE_INIT;
-void
+static void
 init_sample(void)
 {
 	pthread_mutex_init(&sample_mutex, NULL);