bool await(function<void()> cb = []{}) {
		int my_gen = generation.load();
		if (count.fetch_add(1) == N_THREADS - 1) {
			if (cb) cb();
			count.store(0);
			generation.fetch_add(1);
			return true;
		} else {
			do { } while (my_gen == generation.load());
			return false;
		}
	}
Example #2
0
void numberOfFaces(string filePath)
{ 
	if (!instance.get()) {
		CascadeClassifier* face_cascade = new CascadeClassifier();
		face_cascade->load(face_cascade_name);
		instance.reset(face_cascade);
	}

	Mat faceImage = imread(filePath, IMREAD_COLOR);
	if (faceImage.empty()) // Check for invalid input
	{
		cout << "Could not open or find the image" << endl;
		return;
	}

	Mat frame_gray;
	std::vector<Rect> faces;
	cvtColor(faceImage, frame_gray, CV_BGR2GRAY);
	equalizeHist(frame_gray, frame_gray);

	instance->detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
	int numFaces = faces.size();
	//cout << "Found " << numFaces << " faces in image: " << filePath << endl;
	totalFaces.fetch_add(numFaces, boost::memory_order_seq_cst);
	//cout << "Total: " << totalFaces << endl;
	/*if (numFaces > 0)
	{
		drawFaceElipse(faceImage, faces);
	}*/
}
Example #3
0
void atomic2(uint64_t cnt){
  for(uint64_t i=0; i<cnt; i++){
    total2.fetch_add(1);
    total2.fetch_sub(1);
    //total2++;
  }
}
Example #4
0
		handle &create(
			const function<void()> &f){

			auto id = _id.fetch_add(1);
			auto t = make_unique<task>(id, f);
			auto &slot = tasks[id];

			slot = std::move(t);

			return slot->handle;
		}
// Aqui esta a barreira. Ela e uma barreira de propagacao.
static void barrier(int tid, int nthreads) {
     trava.lock();
     if (tid == nthreads-1) {
          itnumber.fetch_add(1);
     }
     order.push_back(tid);
     trava.unlock();
     int sid;
     for (int i = 1; i <= nrounds; ++i) {
          ++arrive[tid];
          // Determina quem a thread vai esperar.
          sid = (tid + power2to(i-1)) % nthreads;
          while (arrive[sid] < arrive[tid]) {
               this_thread::yield();
          }
     }
}