 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Garak
Joined: 27 Jul 2005 Posts: 46
|
Posted: Sun Aug 07, 2005 1:03 pm Post subject: Potential sceKernelExitThread Problem |
|
|
Potential sceKernelExitThread Problem
Greetings,
I have discovered what may be a possible bug in the PSP SDK, or potentially an error on my part. Here is the series of events that leads to my problem:
1. Each time the user clicks the square key, a thread gets started.
2. The thread starts and promptly exits after successfully doing its “bidness”.
3. After I create 20 threads, I can create no more new threads. My call to sceKernelCreateThread return a negative number indicating the thread was not created successfully.
4. As a note, to simplify my example we will say I let each thread finish running before I attempt to start the next one. Also, each thread runs correctly, without errors.
Here is the code used to create my thread:
tId = sceKernelCreateThread("Ball Thread", BallThread, 0x18, 0x10000, 0, 0);
The code to start my thread:
ret = sceKernelStartThread(tId, sizeof(&b), &b);
The prototype for the thread being started:
void BallThread(int size, unsigned int *addr)
Here is what I have concluded from research:
1. If I lower the stack size of my thread (yes, 0x10000 is probably excessive, but that is beside the point), I can create a larger number of threads before program crashes.
2. Based on this fact, it seems the call I have to sceKernelExitThread(0); before my thread exists is not freeing the memory allocated to that thread.
3. If I DO NOT call sceKernelExitThread(0) when my thread finishes, but instead call sceKernelDeleteThread(_tId); from main, I am able to create / destroy as many threads as I like and this problem does not occur.
4. I have tried replacing my call to sceKernelExitThread(0) in the thread itself with a call to sceKernelDeleteThread(_tId); but this does not work. When I try this, I cannot create more than 20 threads.
5. As a side note, when I was using the SDK Beta 1.0 with psptoolchain-20050625.tgz, the exact same code did not have this problem. Now I am using SDK 4.01 with psptoolchain-20050725.tar. Both were Linux builds run in a Win32 env. using Cygwin.
Am I right in assuming I can only create 20 threads because the memory allocated to each thread is not being freed when the thread exists? Is there more to exiting a thread than calling sceKernelExitThread? Any help on this issue would be greatly appreciated.
Garak |
|
| Back to top |
|
 |
mrbrown
Joined: 17 Jan 2004 Posts: 1536
|
Posted: Sun Aug 07, 2005 3:10 pm Post subject: |
|
|
| Answered here. |
|
| Back to top |
|
 |
Garak
Joined: 27 Jul 2005 Posts: 46
|
Posted: Mon Aug 08, 2005 11:56 am Post subject: |
|
|
Yhank you Mr. Brown,
Using sceKernelExitDeleteThread(0); worked great! My current API docs do not even mention this function, but they are from the 1.0 SDK. Is there a more up to date API document I can reference? I have a link to the followjg: http://pspdev.ofcode.com/api.php
but it just contains names and does not even list function paramaters or return values. Thanks again for your help.
Garak |
|
| Back to top |
|
 |
|
|
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
|