- cerr << "Iterating over the children, number: " << children.size() << endl;
- for(vector<Node*>::iterator child = children.begin(); child != children.end(); ++child){
- if ((*child)->satisfyConditions(node->effects())){
- ++executions;
- cerr << "Creating new thread" << endl;
- pthread_attr_t tattr;
- pthread_t tid;
- pthread_attr_init(&tattr);
- pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM);
- ExecutionStuff* es = new ExecutionStuff;
- es->nodes = &_nodes;
- es->list = &_list;
- es->node = *child;
- es->execQueue = &_executedNodes;
- pthread_create(&tid, &tattr, executeNode, es);
- //executeNode(es);
- }
+ executions += executeChildren(node);
+
+ }
+}
+
+
+int Planner::executeChildren(Node* node){
+
+ vector<Node*> children = node->children();
+
+ int executions = 0;
+ //Iterate over the children for this node
+ for(vector<Node*>::iterator child = children.begin(); child != children.end(); ++child){
+ //Satisfy the preconditions the current node had as effect.
+ if ((*child)->satisfyConditions(node->effects())){
+ //If all preconditions were satisified we can create a new thread
+ //and execute this child.
+ ++executions;
+ pthread_attr_t tattr;
+ pthread_t tid;
+ pthread_attr_init(&tattr);
+ pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM);
+ //Create a struct object for the thread and add the
+ //needed members to it.
+ ExecutionStuff* es = new ExecutionStuff;
+ es->nodes = &_nodes;
+ es->list = &_list;
+ es->node = *child;
+ es->execQueue = &_executedNodes;
+ pthread_create(&tid, &tattr, executeNode, es);