#include #include #include using namespace std; class Task { private: int n; float * v; public: Task(int n, float * v):n(n),v(v) {} float * get() { return v; } int length() { return n; } }; template class Queue { private: std::queue tasks; pthread_mutex_t lock; public: Queue() { lock = PTHREAD_MUTEX_INITIALIZER; } ~Queue() { // TBD } void send(Task m) { pthread_mutex_lock(&lock); tasks.push(m); pthread_mutex_unlock(&lock); return; } Task receive() { pthread_mutex_lock(&lock); Task t = (Task) tasks.front(); tasks.pop(); pthread_mutex_unlock(&lock); return t; } }; typedef struct __comms { Queue * in; Queue * out; } COMMS; Task f(Task x) { return x; } void * body(void * x) { COMMS * q = (COMMS *) x; int * i = new int(); while(true) { Task t = (q->in)->receive(); if(t.length() < 0) break; // EOS Task r = f(t); (*i)++; q->out->send(r); } return ((void *) i); } int main(int argc, char * argv []) { Queue tasks; Queue ress; COMMS c; c.in = &tasks; c.out = &ress; int nw = atoi(argv[1]); pthread_t * tid = new pthread_t[nw]; for(int i=0; i