Need some pthread help

I’m dove back into the Frotz code, specifically the new audio code. It seems to be working, but there is a perverse problem with Frotz segfaulting when spawing a thread to play an AIFF sample. I discovered that if I add usleep(0) just after the thread spawn in the main thread, the audio plays as expected. If I try to trace through the code with gdb (using ddd), the bug refuses to show itself. Valgrind memcheck isn’t telling me anything helpful and helgrind also causes the bug to not manifest. I tried a test case program, but that works perfectly. Can I get some help from someone who really knows pthread programming?

github.com/DavidGriffith/frotz/ … ux_audio.c

It kinda looks like you might be passing the address of a local EFFECT variable to the thread in pthread_create, and then immediately exiting from the function that defined the local, thus freeing it out from under the thread.

Duh… I see now. I should use a semaphore instead.

Or malloc in the caller and free after copying in the thread, I suppose.