Job root;
Job job1;
Job job1_1;
Job job1_2;
Job job2(&job1, 1); // job2 cannot start until job1 finishes.
job1.addJob(&job1_1);
job1.addJob(&job1_2);
root.addJob(&job1);
root.addJob(&job2);
root.execute(); // execute the job graph.
I am using pthreads to implement this but I am new to this type of programs and I cant find a way to synchronize all this.
I tried using pthread_join to do something like this :
void Job::execute()
{
for(int i = 0; i < numDependencies; ++i)
dependencies.join(); // calling pthread_join
for(int i = 0; i < numSubJobs; ++i)
subJobs.start(); // calling pthread_create
... do some work here
for(int i = 0; i < numSubJobs; ++i)
subJobs.join(); // calling pthread_join
}
But my program crash in one of the pthread_join call.
[font="Verdana, Arial, Helvetica, sans-serif"]The results of multiple simultaneous calls to pthread_join() specifying the same target thread are undefined.[/font]
[/quote]
How can I achieve the same results but without the crash?
Thanks