You made an array of Thread-pointers using new, and got a pointer to that array. Then you initialize the threads in the next for-loop.Mike Sherwin wrote: ↑Fri Mar 04, 2022 6:39 pmCode: Select all
// Final Thread pointer setup example. // declarations: s32 maxThreads; Thread** thread; Thread* t; // initialization: // must figure out how to get the number of available threads // and then reduce to the number of threads the user request maxThreads = 32; thread = new Thread*[maxThreads]; for (s32 i = 0; i < maxThreads; i++) { thread[i] = new Thread; } t = thread[0];
So now you have this:
Code: Select all
Thread** thread --> [Thread* 0][Thread* 1][Thread* 2]
| | |
V V V
Thread Thread Thread
I might be completely obvious here, but IMHO, you didn't choose the easiest option. Personally I would have just made an array of Thread objects:
Code: Select all
Thread threads[32];
Code: Select all
int x = 32;
Thread *threads = new Thread[x];
Code: Select all
Thread *threads --> [Thread 0][Thread 1][Thread 2]...
Code: Select all
delete[] threads