Potential sceKernelExitThread Problem

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

Moderators: cheriff, TyRaNiD

Post Reply
Garak
Posts: 46
Joined: Wed Jul 27, 2005 1:59 am

Potential sceKernelExitThread Problem

Post by Garak »

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
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Answered here.
Garak
Posts: 46
Joined: Wed Jul 27, 2005 1:59 am

Post by Garak »

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
Post Reply