I want to do a simple gui for an otherwise unglamorous program, but I want to use only code that's already included with C++ (I'm using Fedora with KDE. Someone mentioned QT already, but I couldn't find a good command reference for it). "Back in the day" I would use ascii to represent windows (you remember those ancient DOS utilities right?). That would probably work too if I could only remember the commands for outputting characters to the screen.
Anyway, problem 2. I've threaded a function call using pthread_create and all is well. It execute flawlessly 303 times then gets stuck. I've verified that the loop that the thread call is in continues to function, but the counter I'm using to restrict the number of threads gets stuck which suggests that after a while, the threads are not exiting the function. I don't have the actual code on this computer, but I'll try to approximate here:
Code:
#define THREADS_TO_LAUNCH=1000;
#define MAX_THREADS=20;
int numthreads=0;
int thread_count=0;
void *threaded(void *nothing)
{
...
do some stuff
...
// As the thread exits, the last thing I want to do is decrement
// the number of active threads and increment the number of
// total threads launched
numthreads--;
thread_count++;
}
int main()
{
while (threads_count < THREADS_TO_LAUNCH)
{
if (numthreads < MAX_THREADS)
{
numthreads++;
pthread_create(NULL,NULL,threaded,NULL);
}
}
}
Anyway, the code all works splendidly, but hangs after 303 launches every time. The main loop never ends because the threads stop exiting or stop decrementing the numthreads variable (I can't tell which). Either way, the loop goes on endlessly. Any ideas? This is a very strange error that I'm sure someone else could see instantly, but I just can't.