I have a program with only 2 threads. One is the main thread, the second one is used as a "music processor". The music processor is initially sleeping on a condition variable by calling pthread_cond_wait. The main thread puts the data to be processed by the other thread in a shared variable and wakes up the thread using pthread_cond_signal.
I've build this program on an Ubuntu 16 system and it ran perfectly. I then proceeded to build a GNU system with the latest linux kernel and GLibc 2.17 on which I need this program to run using the LFS 8.2 instructions.
Running it on this system the music processing thread always fails with the "futex facility returned an unexpected error code" message at the call to pthread_cond_wait. That can be causing this? I've looked all over and can't find any explanation.
EDIT
Here's the simplified code:
struct _audio_processor {
/* Other variables
.
.
.
*/
pthread_mutex_t frameAdvanceLock,
queuedEffectsLock;
pthread_cond_t frameAdvanceBarrier;
} __attribute__((packed));
typedef struct _audio_processor * AudioProcessor;
static void * _playbackThreadBody ( register void * p )
{
register AudioProcessor processor = NULL;
processor = (AudioProcessor) p;
while ( processor->audioThreadRunning ) {
pthread_mutex_lock ( & processor->frameAdvanceLock );
/* This is where it INVARIABLY fails. */
pthread_cond_wait ( & processor->frameAdvanceBarrier, & processor->frameAdvanceLock );
pthread_mutex_lock ( & processor->frameAdvanceLock );
/* Rest of the thread (stuff happens here that takes time).
.
.
.
*/
}
return NULL;
};
AudioProcessor CreateAudioProcessor ( void )
{
register AudioProcessor result = NULL;
register int status = -1;
pthread_attr_t attributes;
result = & _mainAudioProcessor;
/*
Other variables initialized here.
.
.
.
*/
pthread_cond_init ( & result->frameAdvanceBarrier, NULL);
pthread_mutex_init ( & result->frameAdvanceLock, NULL );
pthread_mutex_init ( & result->queuedEffectsLock, NULL );
pthread_attr_init ( & attributes );
pthread_attr_setstacksize ( & attributes, 8192 );
status = pthread_create ( & _audioProcessorThread, & attributes, _playbackThreadBody, result );
sched_yield ();
return result;
};
void AudioProcessorPlaybackMusic ( register const AudioProcessor processor )
{
register int status = -1;
pthread_cond_signal ( & processor->frameAdvanceBarrier );
};