Help: Suspend Main and Wakeup another Thread

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
Derek8588
Posts: 62
Joined: Fri Oct 22, 2004 2:14 pm

Help: Suspend Main and Wakeup another Thread

Post by Derek8588 »

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.
User avatar
Lukasz
Posts: 248
Joined: Mon Jan 19, 2004 8:37 pm
Location: Denmark
Contact:

Post by Lukasz »

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

http://java.sun.com/j2se/1.4.2/docs/gui ... ation.html
http://blogs.msdn.com/oldnewthing/archi ... 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
Post Reply