+ sem_init(&_nodes, 0, 1);
+ sem_init(&_list, 0, 1);
+
+ //We've "executed" the start node.
+ _executedNodes.push(_start);
+ int executions = 1;
+
+ //As long as there executed nodes in the queue.
+ while (executions > 0){
+ //Wait for a node to be added to the queue
+ sem_wait(&_nodes);
+ --executions;
+
+ //Pop the first node from the queue.
+ sem_wait(&_list);
+ Node* node = _executedNodes.front();
+ _executedNodes.pop();
+ sem_post(&_list);
+
+ //We don't need to continue if the end node was executed.
+ if (node == _finish)
+ return;
+
+ vector<Node*> children = node->children();
+
+ //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);
+ }
+ }
+
+ }
+ //Clearing the init and goal vectors, new effects will be added below.
+ _init.clear();
+ _goal.clear();
+ Preconditions goal = _finish->preconditions();
+ for (Preconditions::const_iterator precond = goal.begin(); precond != goal.end(); ++precond){
+ _goal.push_back(precond->first);
+ }
+
+ cout << "Unsatisfied preconditions so far: " << _goal.size() << ": ";
+ copy(_goal.begin(), _goal.end(), ostream_iterator<string>(cout, " "));
+ cout << endl;
+
+ //iterator for inserting effects at the end of _init
+ back_insert_iterator<Literals> ii(_init);
+
+ //Iterate throu the nodes, to see what's been done