It is quite old, but this thread was my better option to gathering whether or not I may have had a thread issue, instead of opening an entire new one, since this may actually already have a solution to my problem.
Code: Select all
PSP_MODULE_INFO("LevolAVG", 0, 1, 6);
PSP_MAIN_THREAD_ATTR(0);
PSP_HEAP_SIZE_KB(18*1024);
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return 0;
}
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0x3F40, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
//Functions Definition and Variables Delaration
void show_menu(void);
void show_menu(void)
{
printf("Press circle to load a imge\n");
}
int main()
{
int errorInteger=0;
pspDebugScreenInit();
SetupCallbacks();
sceDisplaySetMode(0, SCREEN_WIDTH, SCREEN_HEIGHT);
EnableGU();
errorInteger=FreeTypeInitial();
if ( errorInteger == 0 )
{
ERRORMSG("Error Error in FreeTypeInitial\n");
}
errorInteger = MovieInitial();
if (errorInteger == 0)
{
ERRORMSG("Error in Movie Initial\n");
}
ScriptFlow("my.txt");
sceKernelSleepThread();
return 0;
}
I added a phony identifier to jesil's ScriptFlow function below. Only for easing the comprehension strain.
Code: Select all
void * ScriptFlow(char *)
{
myAvgThread->MusicPlayThread=sceKernelCreateThread("playmusic",PlayMusicThread,0x8,0x10000,0,0);
if(myAvgThread->MusicPlayThread < 0)
{
ERRORMSG("ERROR: creat startPlay thread failed returned 0x%08X\n", myAvgThread->MusicPlayThread);
}
sceKernelStartThread(myAvgThread->MusicPlayThread,4,&myAvgThread);
sceKerneSleepThread();
}
jesil wrote:Ok it's me .Finally I figure it out .
We should call sceKernelDelayThread() to delay the current thread and let the thread which you want to start run. And in my Music playing thread . I should add delay time to a certain amount , and thus the thread can run perfectly. Maybe different threads demand different delay time ,depending on initialization of the functions .
So it is my experience .Wish it helps somebody .
1.) Okay, so you effectively start the script flow, and then, immediately after it, you put the main thread into sleep mode.
2.) Next, you start another thread, the music thread, and launch it at a decently high priority to avoid anything near real-time. Then, you sleep the main thread
again.
3.) As you continue, you then place a delay at a 10th less than a second, at every instance the separate music thread is
NOT paused in the dead lock.
I also noticed your ScriptFlow() captures the error, and handles it. But, from how it seems, it quickly forgets the thread wasn't able to be started, and follows up on attempting to call a thread that wasn't created successfully.
So, are you saying that this is the proper threading technique?
Code: Select all
int function thread();
void make thread();
void make thread()
{
create thread( function thread);
launch thread( function thread);
sleep main thread();
}
int function thread()
{
don't sleep function thread();
while(1)
{
delaythread(10000);
}
}
int main()
{
make thread();
sleep main thread again();
while(1)
{
delaythread(100000);
}
end program();
}
I noticed you said delay to let the new thread run, so does that mean the main threads delay should come immediately after the launch thread(); where the main thread's sleep call is?
Now, I'm confused, why sleep the thread twice? By trial and error, you can adjust the delay to threads, but when you said you have to delay the primary thread, why is that if it's already placed in a subtle state such as sleep, or anything similar? If sleep isn't sufficient for that, what is the use of it? When would you wake the sleep thread? I think this is valuable information that may actually help me quite a bit, since your error seems a lot like my own at the moment.
http://forums.ps2dev.org/viewtopic.php?p=87015#87015