I have searched a lot about this and I thought I've found the proper way to have a mutex but it seems it's not the case, my PSP freezes. can please someone tell me if I do this correctly:
I have an object that will handle a thread internally let's call it ObjWithThread. This ObjWithThread contains a std::list that needs to be protected with a mutex, as the thread it launches modifies it.
So, I made this ObjWithThread have a semaphore member m_semaid like this:
Code: Select all
m_semaid = sceKernelCreateSema("OWTSema", 0, 1, 1, 0);
Code: Select all
void ObjWithThread::lock()
{
sceKernelWaitSema(m_semaid, 1, 0);
}
void ObjWithThread::unlock()
{
sceKernelSignalSema(m_semaid, 1);
}
Code: Select all
m_threadId = sceKernelCreateThread("OWTThread", OWTfunction, 0x11, 0xFA0, PSP_THREAD_ATTR_USER|PSP_THREAD_ATTR_VFPU, NULL);
Code: Select all
sceKernelStartThread(owt->m_threadId, sizeof(owt), &owt); //owt is a pointer to the ObjectWithThread itself
Code: Select all
void ObjWithThread::OWTfunction(SceSize args, void *argp)
{
ObjWithThread *_this = *((ObjWithThread**) argp);
while(true)
{
_this->lock();
//here I modify the std::list
_this->unlock();
sceKernelDelayThread(500);
}
}
Help...