#include #include #include #include #include #include #include #include #include using namespace std; typedef struct __task { float x; long n; } farm_task_t; mutex locche; list tasks; void worker(int no) { int taskno = 0; thread::id mythreadid = this_thread::get_id(); #ifdef DEBUG cout << "Worker No. " << no << " started (on thread " << mythreadid << ")" << endl; #endif while(true) { farm_task_t t; locche.lock(); if(!tasks.empty()) { t = *(tasks.front()); tasks.pop_front(); locche.unlock(); } else { locche.unlock(); break; // TODO } #ifdef DEBUG cout << "Worker no. " << no << " got task " << t.x << " " << t.n << endl; #endif taskno++; for(long i=0; ix = (float) i; t->n = i*100000L; tasks.push_back(t); } cout << "Tasks created ..." << endl; vector workers; gettimeofday(&t0,NULL); for(int i=0; i