I've actually come across an issue, if anyone can help.
Code:
#include <stdio.h>
#include <process.h>
#include <windows.h>
#include <time.h>
void thread(void *);
int main(int argc, char *argv[]) {
getchar();
double totaltime = clock();
int totaltime2 = time(0);
for(int x = 0; x!=2000; x++) {
_beginthread( thread, 0, (void*)x);
Sleep(9);
}
while(1) {
puts("Main Thread is Sleeping");
printf("Total Time: %.2f\n", (clock()-totaltime)/1000);
printf("Total Time2: %d\n", time(0)-totaltime2);
Sleep(30000);
}
}
void thread(void *arg) {
Sleep((INT_PTR)arg * 9);
printf("Thread%d created.\n", (INT_PTR)arg);
/*
double total = clock();
for (int x = 0; x<=10; x++) {
printf("Thread%d = %d\n", (INT_PTR)arg, x);
}
total = clock() - total;
printf("Thread%d is finished, and now sleeping\n");
Sleep(120000);
printf("Thread%d finished in %.2f seconds\n", (INT_PTR)arg, total/1000 );
*/
Sleep(60000);
printf("Thread%d is being destroyed.\n", (INT_PTR)arg);
}
***The Problem:
My limit is 891 threads. I need to be able to create more. I'm doing research to find out how to change this. With no luck. My console gives me the message of only 889 created, and thread 889 destroyed.
My Resource Monitor shows 891. :|
I am using my favorite compiler: BloodShed Dev-C++.. I'll probably upgrade to V.5 beta later. Maybe that'll change it. But any other ideas on the problem would be great!
----------------
***Answer::
Found answer.
It assigns itself a set amount of space. Once that space is filled, it cannot give anymore set addresses. Therefore will fail in creating more threads. It's interesting, and I need to find a way to...
***New Problem:
Change the size of the allocated space when creating the new thread.
Some threads need lots of space, while others.. very very very little space. Like, 50 bytes MAX. Those threads would be for calculating time.. only. When the time is up, sending a signal somewhere. But nothing else.
Now.. where can I find a way to change the space upon creation? --- humm..
Keep reading I suppose.
***Not the answer..
_beginthread( thread, 0, (void*)x);
thread -- function to start thread with. (Not sure how to pass additional parameters?)
0, -- Size of thread stack (in bytes according to:
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
Tried changing it to 10, and 20. No difference to max threads.
(void*)x -- Thread number (like a reference). Important if you use different numbers for each thread. I used it in terms of a loop. So.. yea.