Ejemplo n.º 1
0
int safety(){
	int i , j;
	copyFromTo(AVAILABLE,WORK);
	int *finish = (int *) malloc(sizeof(int ) * n);
	
	while((i = find(finish, WORK, NEED )) != -1){
		for(j = 0;j<m;j++){
			WORK[j] += ALLOCATION[i][j];
		}
		finish[i] = 1;
		printf("%d just completed\n", i);
		if( allFinished(finish))
			break;
	
	}

	if(!allFinished(finish)){
		printf("unsafe");
		return 0;
	}
	else{
		printf("safe");
		return 1;
	}

}
void *threadFunc(void *arg){
	struct cart_t *cart;
	struct queue_info *info = (struct queue_info *)arg;
	fprintf(stderr, "thread for direction %c starts\n", info->dir);

  pthread_barrier_wait(&barrier);

	cart = q_getCart(info->dir);
	while(1){
    if(allFinished() == 1) break;
    if(cart == NULL){
      finishes[info->thread_index] = 1;
    }
    else{
      fprintf(stderr, "thread for direction %c gets cart %i\n", info->dir, cart->num);
      monitor_arrive(cart);
      monitor_cross(cart);
      monitor_leave(cart);
      cart = q_getCart(info->dir);
    }
	}

	fprintf(stderr, "thread for direction %c exits\n", info->dir);
	pthread_barrier_wait(&barrier);

	return (void *) 1;
}
Ejemplo n.º 3
0
QDispatchGroup::QDispatchGroup (
    const xdispatch::group &obj
)
    : xdispatch::group( obj ),
      d( new Private() )
{
    connect( d.data(), SIGNAL( groupFinished() ), this, SIGNAL( allFinished() ) );
}
Ejemplo n.º 4
0
QDispatchGroup::QDispatchGroup (
    dispatch_group_t o
)
    : xdispatch::group( o ),
      d( new Private() )
{
    connect( d.data(), SIGNAL( groupFinished() ), this, SIGNAL( allFinished() ) );
}
Ejemplo n.º 5
0
int performBankersAlgorithm(int *tmpNeed, int *tmpWork, int *tmpAllocation, int *isFinishedProc, int numProc, int numRes)
{
  int i;
  int isNotSafe;
  int didNothing;
  
  i = 0;
  isNotSafe = 1;

  /* While we are not yet in a safe state, try to find a process whereby
     Need_i <= Work */
  while(isNotSafe)
  {
    i = 0;
    /* didNothing is a simple flag that lets us know if the process has allocated
       any resources during the current loop iteration */
    didNothing = 0;
    while (i < numProc)
    {
      /* try to find a process whereby
         Need_i <= Work and the current process is not finished yet*/
      if (!isFinishedProc[i] && safeToAllocate(tmpWork, tmpNeed, numRes, i*numRes))
      {
        /* We found such a process, so set the process to finished and
           release its allocated resources back to work */
        isFinishedProc[i] = 1;
        incrementWork(tmpWork, tmpAllocation, i*numRes, numRes);
        /* We did something so set the flag to 1 */
        didNothing = 1;
      }
      i++;
    }
    if (!didNothing)
    {
      /* Since we did nothing in this loop iteration, check if all processes
         are finished, and if so, declare safe state */
      if (allFinished(numProc, isFinishedProc))
      {
        /* Set isNotSafe to false since we returned a safe state ! */
        isNotSafe = 0;
      }
      break;
    }
  }

  if (isNotSafe)
  {
    /* We are not in a safe state, so return 0. */
    return 0;
  }
  else
  {
    /* We are in a safe state, so return 1. Passed Banker's Algorithm */
    return 1;
  }
  

}
void MediaIndexer::finished(int exitCode, QProcess::ExitStatus exitStatus)
{
    m_status["description"] = QString();
    m_status["progress"] = -1;
    emit updateStatus(m_status);
    emit finished();
    m_state = Idle;
    emit allFinished();
    Q_UNUSED(exitCode);
    Q_UNUSED(exitStatus);
}
Ejemplo n.º 7
0
    void WritingOrchestrator::onWorkerFinished(bool anyError) {
        Exiv2WritingWorker *worker = qobject_cast<Exiv2WritingWorker *>(sender());
        Q_ASSERT(worker != NULL);

        LOG_INFO << "#" << worker->getWorkerIndex() << "anyError:" << anyError;

        worker->dismiss();

        if (m_FinishedCount.fetchAndAddOrdered(1) == (m_ThreadsCount - 1)) {
            LOG_DEBUG << "Last worker finished";
            emit allFinished(!m_AnyError);
        }
    }
Ejemplo n.º 8
0
void WebPuppeteerTab::waitFinish(int idle) {
	QEventLoop e;
	TimeoutTrigger t(idle);

	connect(&t, SIGNAL(timeout()), &e, SLOT(quit()));
	connect(networkAccessManager(), SIGNAL(started()), &t, SLOT(start()));
	connect(networkAccessManager(), SIGNAL(allFinished()), &t, SLOT(end()));

	// if something pending, stop timer
	if (static_cast<WebPuppeteerTabNetSpy*>(networkAccessManager())->getCount() > 0)
		t.start();

	e.exec();
}
Ejemplo n.º 9
0
void WebEngine::heartbeat()
{
    // first see if there's a new query to be submitted.
    auto it = std::find_if(std::begin(m_live), std::end(m_live),
        [](const std::unique_ptr<WebQuery>& query) {
            return !query->isActive() && !query->isAborted();
        });
    if (it != std::end(m_live))
    {
        auto& query = *it;
        query->submit(m_qnam);
    }

    // remove queries that were aborted before being submitted.
    auto end = std::remove_if(std::begin(m_live), std::end(m_live),
        [&](const std::unique_ptr<WebQuery>& query) {
            return query->isAborted();
        });
    m_live.erase(end, std::end(m_live));


    // important: if we manually timeout() a webquery the finished signal for the
    // query will be emitted. This is exactly what we want since basically this 
    // means that the query completed/finished but with *errors*. 
    // However we must be careful since the same callback is also used for 
    // succesful queries and in those cases it deletes the query object
    // not to mess up our iteration here!

    // tick live queries and abort the ones that have timed out.
    for (auto it = std::begin(m_live); it != std::end(m_live); )
    {
        auto& query = *it;
        // if not yet active (i.e. submitted), skip it.
        if (!query->isActive())
        {
            ++it;
            continue;
        }

        // update the tick, returns true if still within timeout treshold.
        if (query->tick(m_timeout))
        {
            ++it;
            continue;
        }

        // timeout the query.
        // see the comments above about the signal handler.
        //query->timeout();
        m_dead.push_back(std::move(*it));
        it = m_live.erase(it);
    }

    if (!m_dead.empty())
    {
        DEBUG("Deleting timedout queries");

        // doesn't f***N disconnect!
        //QObject::disconnect(&m_qnam, SIGNAL(finished(QNetworkReply*)));
        //QObject::connect(&m_qnam, SIGNAL(finished(QNetworkReply*)),
        //    this, SLOT(timedout(QNetworkReply*)));

        for (auto& carcass : m_dead)
        {
            auto& query = carcass;
            query->timeout();
        }

        // QObject::disconnect(&m_qnam, SIGNAL(finished(QNetworkReply*)));
        // QObject::connect(&m_qnam, SIGNAL(finished(QNetworkReply*)),
        //     this, SLOT(finished(QNetworkReply*)));

        m_dead.clear();
    }

    if (m_live.empty())
    {
        m_timer.stop();
        emit allFinished();
    }
}
Ejemplo n.º 10
0
void WebPuppeteerTabNetSpy::spyFinished(QNetworkReply*) {
	cnx_count--;
	if (cnx_count == 0)
		allFinished();
}
Ejemplo n.º 11
0
void QueryTester::runInThread()
{
    initResources();
    connect(resultChecker, SIGNAL(allFinished()), this, SLOT(quit()));
    startQueries();
}
Ejemplo n.º 12
0
QDispatchGroup::QDispatchGroup ()
    : d( new Private() )
{
    connect( d.data(), SIGNAL( groupFinished() ), this, SIGNAL( allFinished() ) );
}