Beispiel #1
0
void *estimate(void *param)
{
  FILE *fptr = (FILE *)param;
  char coeff[MAX_CHAR];
  int t = 1;

  while(NULL != fgets(coeff, MAX_CHAR, fptr)) {
    float a = atof(strtok(coeff, ","));
    float b = atof(strtok(NULL, ","));
    float c = atof(strtok(NULL, ","));
    float d = atof(strtok(NULL, ","));

    for(int i=1 ; i < 10 ; ++i) {
      m_queue.push(a * pow(t + i * 0.1, 3) +
		   b * pow(t + i * 0.1, 2) +
		   c * (t + i * 0.1) +
		   d);
    }

    // increase time
    ++t;
  }

  // set cstat as false
  m_est_cstat = false;
  // wait signal
  pthread_cond_wait(&m_est_cvar, &m_est_mutex);

  // exit from thread
  pthread_exit(NULL);

  return NULL;
}
    void operator()( long thread_id ) const {
        long pop_kind[3] = {0,0,0};
        int serial[MAXTHREAD+1];
        memset( serial, 0, nthread*sizeof(unsigned) );
        ASSERT( thread_id<nthread, NULL );

        long sum = 0;
        for( long j=0; j<M; ++j ) {
            Foo f;
            f.thread_id = DEAD;
            f.serial = DEAD;
            bool prepopped = false;
            if( j&1 ) {
                prepopped = queue->pop_if_present(f);
                ++pop_kind[prepopped];
            }
            Foo g;
            g.thread_id = thread_id;
            g.serial = j+1;
            queue->push( g );
            if( !prepopped ) {
                queue->pop(f);
                ++pop_kind[2];
            }
            ASSERT( f.thread_id<=nthread, NULL );
            ASSERT( f.thread_id==nthread || serial[f.thread_id]<f.serial, "partial order violation" );
            serial[f.thread_id] = f.serial;
            sum += f.serial-1;
        }
        Sum[thread_id] = sum;
        for( int k=0; k<3; ++k )
            PopKind[k] += pop_kind[k];
    }
Beispiel #3
0
void schedule(size_t i) {
    std::unique_lock<std::mutex> lock(g_work_mutex);
    g_work_queue.push(i);
    g_work_condition.notify_one();
    while (not g_work_queue.empty()) {
        g_work_condition.wait(lock);
    }
}
Beispiel #4
0
		void operator() (const tbb::blocked_range<int>& range) const {
			for(int i = range.begin();i != range.end(); i++)
				todo->push(std::make_pair((*nodes)[curr.first].edges[i],curr.second+1));
		}
Beispiel #5
0
 void enqueue(job_type* job)
 {
     m_queue.push(job);
     m_logger << m_queue.unsafe_size();
 }
Beispiel #6
0
 void schedule (const Task & task)
 {
     POMAGMA_ASSERT(m_accepting.load(), "pool is not accepting work");
     m_queue.push(task);
     m_condition.notify_one();
 }