Limit the number of threading being threaded

Hey guys I'm trying to do threading in to solve a maze algorithm.
The catch is this, the max "life" of the thread is 3.
So if the thread hit a danger spot, lets say "X".
The system will exit.
I'm able to solve the algorithm but I don't know how to set the thread process limit.
Anyone care to teach me? Thx!!

Since the code are way too long, I show the part where there create the thread.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int threadGen() {

    pthread_t thread1, thread2;
    string thread_Msg1 = "A new Thread has been created!!!";
    string * thread_message = &thread_Msg1;

    if (pthread_create(&thread1, NULL, mSolve, thread_message) != 0) {
        return EXIT_FAILURE;
    } else {
        cout << thread_Msg1 << endl;
    }

    if (pthread_join(thread1, NULL) != 0) {
        return EXIT_FAILURE;
    }
    //print solution
    if (!submitted && submitPath) {

        sms.printSubmittedSolution("Success", "12345");
        submitted = true;
    }
    return EXIT_SUCCESS;
}
Consider using the C++11 (formerly 0x) thread objects.
With that you can do all these much more easily.
And you can.. for example.. keep a counter.. of the objects and stop generating more as you wish.
Topic archived. No new replies allowed.