[RESOLVED] Threads and Modules

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
BigProMaN
Posts: 16
Joined: Fri Aug 29, 2008 9:37 pm

[RESOLVED] Threads and Modules

Post by BigProMaN »

Hello All !

So, I've got a little problem in my code, here it is (this is not the entire code) :

Code: Select all

int main(int args, char** argv)
{

	.....

	DisplayThread = sceKernelCreateThread("...", Display_Thread, 0x18, 0x10000, PSP_THREAD_ATTR_USER, NULL);
	sceKernelStartThread(DisplayThread, 0, 0);
	
	int i;
	
	while(1)
	{
		Ctrl(); //Control
	}

        return 0;
}

void Ctrl()
{
         if (pad.Buttons & SelectKey && !(oldPad.Buttons & SelectKey))
	{
                   ....
                  sceKernelStartModule(usbcam,
                  strlen("ms0:/usbCam.prx")+1,"ms0:/UsbCam.prx", NULL, NULL);

		sceKernelSuspendThread(DisplayThread); //I suspend my display thread to blit my module correctly
        }
         
       if (pad.Buttons & CancelKey && !(oldPad.Buttons & CancelKey))
	{
                   ....
                  sceKernelStopModule(usbcam,strlen("ms0:/usbCam.prx")+1,"ms0:/UsbCam.prx", NULL, NULL);

		 sceKernelResumeThread(DisplayThread); // Now I can Resume my Thread
        }

        ... //Other controls ...

The problem is : before I start my module the controls work perfectly. Then I start my module, and when I press Circle, the module is stopped and I resume my display thread. The thread re-appear on the screen normally, but this time the controls don't work :(

I don't know if I'm very clear ^^ In fact, as soon as I stop the module, the controls don't work.

Thanks in advance :p

PS:Sorry for my bad English
Last edited by BigProMaN on Tue Jan 06, 2009 3:04 am, edited 1 time in total.
Excuse me for my English, I'm French.
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Post by ne0h »

mmm... I can't see a little sceCtrl call...
Are you reading control buffers in the "entire" code?
BigProMaN
Posts: 16
Joined: Fri Aug 29, 2008 9:37 pm

Post by BigProMaN »

Oh Yes, I forgot this function.
sceCtrlReadBufferPositive(&pad,1) is called in Ctrl();
Excuse me for my English, I'm French.
cosmito
Posts: 307
Joined: Sun Mar 04, 2007 4:26 am
Location: Portugal
Contact:

Re: Threads and Modules

Post by cosmito »

BigProMaN wrote:PS:Sorry for my bad English
_________________
Excuse me for my English, I'm French.
Why everyone nowadays seems to be sorry about their english?! Is it so important really to have a *perfect* english?
His text seems perfectly understandable...
(sorry for the off-topic comment, but sometimes this matter p*ss me off...)
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Re: Threads and Modules

Post by J.F. »

cosmito wrote:
BigProMaN wrote:PS:Sorry for my bad English
_________________
Excuse me for my English, I'm French.
Why everyone nowadays seems to be sorry about their english?! Is it so important really to have a *perfect* english?
His text seems perfectly understandable...
(sorry for the off-topic comment, but sometimes this matter p*ss me off...)
They're just worried they'll be mistaken for a stupid American... which is a valid concern. I once submitted a review of some fanfiction where I suggested the author try to get someone who spoke/wrote English natively to help him with his writing as I assumed his truly dreadful English was the result of trying to use the truly dreadful language translation sites out. The guy wrote me back a blistering email that was 99% vulgarities because I had apparently insulting his writing skills - turns out, he wasn't a foreigner using bad translation software, he was 100% US citizen... in fact, he claimed to be a college student working on a Masters in English writing! Whoopsie! Considering he wrote below a third grade level with atrocious grammar and spelling, I could only hope he was lying about being an English student at a major university.

So if someone apologies for their English, claiming to be foreign, I just tell them it's fine, that their English is much better than my <whatever language> and leave it at that. :D
BigProMaN
Posts: 16
Joined: Fri Aug 29, 2008 9:37 pm

Post by BigProMaN »

Excuse me cosmito ... I forgot that my signature was already "Excuse me for my bad English" ^^

Has anybody got the solution ?
Excuse me for my English, I'm French.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

What kind of waiting are you doing in the Ctrl function? Your while loop simply calls Ctrl over and over, so if Ctrl isn't doing any waiting, nothing but Ctrl is running. The PSP uses coop multitasking, so only one thing runs until you call something that allows others to run. You'd want something like an sceKernelDelayThread(33333); in the loop somewhere so that other threads can run.
Smong
Posts: 82
Joined: Tue Sep 04, 2007 4:44 am

Post by Smong »

I think sceCtrlReadBufferPositive does allow other threads to run. While sceCtrlPeekBufferPositive does not.
(+[__]%)
NoEffex
Posts: 106
Joined: Thu Nov 27, 2008 6:48 am

Post by NoEffex »

Smong wrote:I think sceCtrlReadBufferPositive does allow other threads to run. While sceCtrlPeekBufferPositive does not.
Nah, I use peekbuffer and it lets the other threads run fine.
Programming with:
Geany + Latest PSPSDK from svn
Smong
Posts: 82
Joined: Tue Sep 04, 2007 4:44 am

Post by Smong »

In that case I may have to double check it. Is that the only firmware function you are calling from your mainloop? Some other function may be allowing threads to get a chance at running.
(+[__]%)
BigProMaN
Posts: 16
Joined: Fri Aug 29, 2008 9:37 pm

Post by BigProMaN »

Finnally the problem is revolved ...
I had to call pspSdkLoadStartModule when I press X, and call sceKernelSelfStopUnloadModule directly in the module loaded to stop/unload it :)
Excuse me for my English, I'm French.
Smong
Posts: 82
Joined: Tue Sep 04, 2007 4:44 am

Post by Smong »

NoEffex wrote:
Smong wrote:I think sceCtrlReadBufferPositive does allow other threads to run. While sceCtrlPeekBufferPositive does not.
Nah, I use peekbuffer and it lets the other threads run fine.
Smong wrote:In that case I may have to double check it.
I double checked by calling sceCtrlPeekBufferPositive 1mil times while a 2nd thread was in the ready state and the 2nd thread never got a chance to run. And just to make sure I repeated the test with sceCtrlReadBufferPositive which did let the 2nd thread run. So I will assume you are calling other firmware functions, at least one of which does having a blocking behaviour.
(+[__]%)
Post Reply