#ifndef ParallelH
#define ParallelH

#include <pthread.h>
#include <semaphore.h>

template <typename T>
class ConcurrentQueue : public std::queue<T> {
private:
	pthread_mutex_t lock;
	sem_t sem;
public:
	ConcurrentQueue() {
		sem_init(&sem, 0, 0);
		pthread_mutex_init(&lock, NULL);
	}

	~ConcurrentQueue() {
		pthread_mutex_destroy(&lock);
		sem_destroy(&sem);
	}

	void push(const T& t) {
		pthread_mutex_lock(&lock);
		std::queue<T>::push(t);
		pthread_mutex_unlock(&lock);
		sem_post(&sem);
	}

	void pop(T& t) {
		sem_wait(&sem);
		pthread_mutex_lock(&lock);
		t = std::queue<T>::front();
		std::queue<T>::pop();
		pthread_mutex_unlock(&lock);
	}
};

//typedef RWLockList<Term> TermList;
typedef std::list<Term> TermList;
typedef ConcurrentQueue<Term> TermQueue;

#endif
