forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help: Suspend Main and Wakeup another Thread

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development
View previous topic :: View next topic  
Author Message
Derek8588



Joined: 22 Oct 2004
Posts: 62

PostPosted: Sat Sep 20, 2008 12:19 am    Post subject: Help: Suspend Main and Wakeup another Thread Reply with quote

I have created a simple app that sets up a vblank handler and creates a thread. What I am trying to do is when a certain condition is met within the vblank handler, it calls iSuspendThread() on my main thread and then calls iWakeupThread on the thread I created. Mains priority = 64 and my threads priority = 4. And once the Thread finished it will call ResumeThread on main. In other words, I am trying to halt main, execute a thread, and return to main without having to manually call SleepThread() within main.

For test purposes, if I manually call SleepThread() within main and then have my vblank handler call iWakeupThread() on my thread, my thread runs fine no problems. But if I dont manually call SleepThread within main, and in my handler call iSuspendThread() on main and then iWakeupThread on my thread, my thread doesnt run... Why is this, I dont understand why it's not working. Any suggestions? Thanks

Edit: one more question. How can I put a thread in WAIT state other then calling StartThread(); on it. StartThread actually runs the thread immediately. I just want it to sit in wait state until I call iWakeupThread() on it. Thanks again for your time and patience.
Back to top
View user's profile Send private message
Lukasz



Joined: 19 Jan 2004
Posts: 248
Location: Denmark

PostPosted: Sat Sep 20, 2008 6:46 pm    Post subject: Reply with quote

Generally suspending a thread is considered a bad thing, a couple of references:

http://java.sun.com/j2se/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html
http://blogs.msdn.com/oldnewthing/archive/2003/12/09/55988.aspx

What you want to do on the PS2 is either use a semaphore or SleepThread to put your thread into wait state.

As for having your thread wait for iWakeThread, I think the best solution would be to either use SleepThread or WaitSema in the beginning of the thread.

Also remember that the PS2 uses cooperative multitasking, a couple of threads about the subject:

http://forums.ps2dev.org/viewtopic.php?t=9411
http://forums.ps2dev.org/viewtopic.php?t=10294
_________________
Lukasz.dk
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group