When the Core thread safety is disabled with the FMOD_INIT_THREAD_UNSAFE
flag and the funcForDifferentThread() is called “from different threads multiple times”, will the below pseudocode work?
class MySound {
float curVol = 1.0f;
MySound() {
FMOD_System_PlaySound(TRUE);
FMOD_Channel_SetVolume(curVol);
FMOD_System_CreateDSPByType();
FMOD_DSP_SetParameterFloat();
FMOD_Channel_AddDSP();
FMOD_Channel_SetPaused(FALSE);
}
~MySound() {
FMOD_Channel_Stop();
FMOD_DSP_Release();
}
bool decreaseVolume() {
curVol -= 0.1f;
if (curVol <= 0)
return false;
FMOD_Channel_SetVolume(curVol);
return true;
}
};
void funcForDifferentThread() {
pthread_mutex_lock(&myMutex);
MySound mySound = new MySound();
soundList.add(mySound);
pthread_mutex_unlock(myMutex);
}
void backgroundThreadFunc() {
while (true) {
pthread_mutex_lock(&myMutex);
foreach(each in soundList) {
if (each->decreaseVolume() == false) {
soundList.remove(each);
delete(each);
}
}
FMOD_System_Update();
pthread_mutex_unlock(myMutex);
sleep(2000);
}
}