예제 #1
0
파일: annot.c 프로젝트: koraa/annot
int main(int argc, char** argv) {
  recyclr = newLL();
  inQ = newLL();
  timeQ = newLL();

  ArgRead  ar = {'\n', stdin};
  ArgTime  at = {CLOCK_MONOTONIC};
  ArgPrint ap = {'\n', stdout};

  // Run the program

  Thread
    *tr = newThread(NULL, thr_read, &ar),
    *tt = newThread(NULL, thr_time, &at);
  thr_print(&ap);

  // We exit soon, still run deletion,
  // to clean up possible FDs and do some
  // error checking

  deleteThread(tr);
  deleteThread(tt); 

  deleteLL(recyclr);
  deleteLL(inQ);
  deleteLL(timeQ);

  return 0;
}
예제 #2
0
static void
delete_all(void)
{
    if (!L4_IsNilThread(prio7_thread)) {
        deleteThread(prio7_thread);
    }
    deleteThread(prio4_thread);
    if (!L4_IsNilThread(prio5_thread)) {
        deleteThread(prio5_thread);
    }
    deleteThread(prio2_thread);
    if (!L4_IsNilThread(prio1_thread)) {
        deleteThread(prio1_thread);
    }
    if (!L4_IsNilThread(prio6_thread)) {
        deleteThread(prio6_thread);
    }
    if (!L4_IsNilThread(prio6bis_thread)) {
        deleteThread(prio6bis_thread);
    }
    if (!L4_IsNilThread(prio8_thread)) {
        deleteThread(prio8_thread);
    }
    deleteThread(main_thread);
    deleteThread(measure_thread);
}
예제 #3
0
파일: thread.cpp 프로젝트: aoshimanoa/apery
void ThreadPool::exit() {
  // checkTime() がデータにアクセスしないよう、先に timer_ を delete
  deleteThread(timer_);

  for (auto elem : *this)
    deleteThread(elem);
}
예제 #4
0
파일: smt.c 프로젝트: BruceYi/okl4
END_TEST

START_TEST(SMT0304)
{
    int j, i;
    L4_ThreadId_t rthread[6];

    // smt0303 but with deletes in reverse order

    pingpong_cleanup = 0;
    pingpong_counter = 0;

    for (j=0;j<TEST3_MAJOR_ITERATIONS;j++) {
        changeThreadCreationSMTBitmask(2);
        rthread[0] = createThreadInSpace(L4_nilthread, (void *)synch_pong);

        changeThreadCreationSMTBitmask(63);
        for(i=0;i<TEST303_MINOR;i++) {
            rthread[i+1] = createThreadInSpace(L4_nilthread, (void *)synch_ping);
        }

        /* Give threads time to start up or our pager may complain
         *  about us going away.
         */
        L4_ThreadSwitch(main_thread);
        sleep_a_bit();
        sleep_a_bit();

        for(i=0; i<TEST303_MINOR; i++)
            deleteThread(rthread[i+1]);

        deleteThread(rthread[0]); // delete pong
    }
}
예제 #5
0
파일: smt.c 프로젝트: BruceYi/okl4
END_TEST

#define TEST303_MINOR 4
/*
\begin{test}{SMT0303}
  \TestDescription{Thread unwind of sending threads}
  \TestFunctionalityTested{Global scheduler, thread creation and deletion}
  \TestImplementationProcess{
    This is a thrashing ping pong.
    The following process is repeated:
    \begin{enumerate}
      \item Create one threads running IPC pong thread. This thread is
      constrained to one hardware thread.
      \item Create four IPC ping threads. These threads are not constrained.
      \item The pong thread is deleted.
      \item The remaining threads are then deleted.
    \end{enumerate}
    The main threads are constrained to running on hardware thread 0.

}
  \TestImplementationStatus{Implemented}
  \TestIsFullyAutomated{Yes}
  \TestRegressionStatus{In regression test suite}
  \TestNotes{Hardware constraint specification is only used on supported
    architectures. For others, the threads will execute round robin.}
    \TestSeeAlso{See document \emph{L4 SMT Support} 10020:2005}
\end{test}
*/
START_TEST(SMT0303)
{
    int j, i;
    L4_ThreadId_t rthread[6];

    pingpong_cleanup = 0;
    pingpong_counter = 0;

    for (j=0;j<TEST3_MAJOR_ITERATIONS*4;j++) {
        changeThreadCreationSMTBitmask(2);
        rthread[0] = createThreadInSpace(L4_nilthread, (void *)synch_pong);

        changeThreadCreationSMTBitmask(63);
        for(i=0;i<TEST303_MINOR;i++) {
            rthread[i+1] = createThreadInSpace(L4_nilthread, (void *)synch_ping);
        }

        /* Give threads time to start up or our pager may complain
         *  about us going away.
         */
        sleep_a_bit();
        sleep_a_bit();

        deleteThread(rthread[0]); // delete pong

        for(i=0; i<TEST303_MINOR; i++)
            deleteThread(rthread[i+1]);
    }
}
예제 #6
0
파일: thread.cpp 프로젝트: autotrad/apery
void ThreadPool::exit() {
#if defined LEARN
#else
	// checkTime() がデータにアクセスしないよう、先に timer_ を delete
	deleteThread(timer_);
#endif

	for (auto elem : *this)
		deleteThread(elem);
}
예제 #7
0
파일: smt.c 프로젝트: BruceYi/okl4
END_TEST

/*
\begin{test}{SMT0302}
  \TestDescription{Thread creation and deletion of ping pong threads}
  \TestFunctionalityTested{Global scheduler, thread creation and deletion}
  \TestImplementationProcess{
    The following process is repeated:
    \begin{enumerate}
      \item Create two threads running IPC ping pong. Each thread is
      constrained to run on separate unused hardware threads.
      \item The threads are deleted.
    \end{enumerate}
    The main threads are constrained to running on hardware thread 0.

}
  \TestImplementationStatus{Implemented}
  \TestIsFullyAutomated{Yes}
  \TestRegressionStatus{In regression test suite}
  \TestNotes{Hardware constraint specification is only used on supported
    architectures. For others, the threads will execute round robin.}
    \TestSeeAlso{See document \emph{L4 SMT Support} 10020:2005}
\end{test}
*/
START_TEST(SMT0302)
{
    int j;
    L4_ThreadId_t rthread[5];

    pingpong_cleanup = 0;

    for (j=0;j<TEST3_MAJOR_ITERATIONS;j++) {
        changeThreadCreationSMTBitmask(2);
        rthread[0] = createThreadInSpace(L4_nilthread, (void *)synch_pong);
        changeThreadCreationSMTBitmask(4);
        rthread[1] = createThreadInSpace(L4_nilthread, (void *)synch_ping);

        /* Give threads time to start up or our pager may complain
         *  about us going away.
         */
        L4_ThreadSwitch(main_thread);
        sleep_a_bit();
        L4_ThreadSwitch(main_thread);

        /* alternate deleting threads first */
        deleteThread(rthread[(j+1)%2]);
        deleteThread(rthread[j%2]);
    }
}
예제 #8
0
파일: smt.c 프로젝트: BruceYi/okl4
END_TEST

/*
\begin{test}{SMT0500}
  \TestDescription{IPC Ping pong constrained to same hardware thread}
  \TestFunctionalityTested{Global scheduler, IPC}
  \TestImplementationProcess{
    Two threads are created and constrained to the same hardware thread.
    This test passes if progress is made.
}
  \TestImplementationStatus{Implemented}
  \TestIsFullyAutomated{Yes}
  \TestRegressionStatus{In regression test suite}
  \TestImplementationStatus{Implemented}
  \TestIsFullyAutomated{Yes}
  \TestRegressionStatus{In regression test suite}
  \TestNotes{Hardware constraint specification is only used on supported
    architectures. For others, the threads will execute round robin.}
    \TestSeeAlso{See document \emph{L4 SMT Support} 10020:2005}
\end{test}
*/
START_TEST(SMT0500)
{
    L4_ThreadId_t rthread[2];


    pingpong_cleanup = 0;
    pingpong_counter = 0;

    changeThreadCreationSMTBitmask(8);
    rthread[0] = createThreadInSpace(L4_nilthread, (void *)synch_pong);
    rthread[1] = createThreadInSpace(L4_nilthread, (void *)synch_ping);

    L4_ThreadSwitch(main_thread);
    sleep_a_bit();
    sleep_a_bit();
    sleep_a_bit();
    sleep_a_bit();
    sleep_a_bit();

    printf("ppc %d\n", pingpong_counter);

    deleteThread(rthread[0]);
    deleteThread(rthread[1]);


    fail_unless(pingpong_counter > 10, "poor smt ping pong result\n");
}
예제 #9
0
    int MapServer::run(void)
    {
        Request::setCoutMutex(&_coutMutex);
        TextDisplayer::setCoutMutex(&_coutMutex);
        SvgCreator::setCoutMutex(&_coutMutex);

        _timeoutReference = time(0);

        std::thread deleteThread(&MapServer::cleanThreads, this);
        std::thread timeoutThread(&MapServer::checkTimeout, this, _softExit);
        if (_softExit) timeoutThread.join();

        inputLoop();

        if (!_softExit) exit(0);

        _threadSetMutex.lock();
        _stopRequested = true;
        _threadSetMutex.unlock();

        deleteThread.join();

        TextDisplayer::clearClientMap();

        return 0;
    }
예제 #10
0
파일: mutex.c 프로젝트: BruceYi/okl4
END_TEST

/*
\begin{test}{MUTEX0407}
  \TestDescription{Delete thread about to acquire a mutex.}
  \TestFunctionalityTested{\Func{L4\_Lock} and \Func{L4\_ThreadControl}}
  \TestImplementationProcess{
    \begin{enumerate}
        \item Create a mutex.
        \item Lock the created mutex.
        \item Create a second thread that attempts to lock the mutex.
        \item Release the mutex.
        \item Delete that thread.
    \end{enumerate}
  }
  \TestPassStatus{pass}
  \TestImplementationStatus{Implemented}
  \TestRegressionStatus{In regression test suite}
\end{test}
*/
START_TEST(MUTEX0407)
{
    L4_Word_t res;
    L4_ThreadId_t child;

    res = okl4_kmutexid_allocany(mutexid_pool, &m);
    fail_unless(res == OKL4_OK, "Failed to allocate any mutex id.");
    /* Create a mutex. */
    res = L4_CreateMutex(m);
    fail_unless(res == 1, "L4_CreateMutex() failed");

    /* Lock the mutex. */
    res = L4_Lock(m);
    fail_unless(res == 1, "L4_Lock() failed");

    /* Get our child to lock the mutex. */
    child = createThread(mutex0406_child_thread);
    L4_Set_Priority(child, 255);
    L4_ThreadSwitch(child);

    /* Restore the priority to below us. */
    L4_Set_Priority(child, 1);

    /* Release the mutex. */
    res = L4_Unlock(m);

    /* Delete our child. */
    deleteThread(child);

    /* Ensure we can still acquire/release the lock. */
    res = L4_Lock(m);
    fail_unless(res == 1, "L4_Lock() failed");
    res = L4_Unlock(m);
    fail_unless(res == 1, "L4_Unlock() failed");
    res = L4_DeleteMutex(m);
    fail_unless(res == 1, "L4_DeleteMutex() failed");
    okl4_kmutexid_free(mutexid_pool, m);
}
예제 #11
0
void uVision::createThumbnail(const QString& filename)
{
	//qDebug() << filename;
	QThread* thread = new thumbnailthread(filename, 10 - waitseconds);
	waitseconds ++;
	connect(thread,SIGNAL(thumbnailFinishedInstitch(QImage)),this,SLOT(addInstitchImages(QImage)));
	connect(thread, SIGNAL(thumbnailFinished(QImage)), this, SLOT(addThumbnail(QImage)));
	connect(thread, SIGNAL(thumbnailFailed(const QString)), this, SLOT(showError(const QString)));
	connect(thread, SIGNAL(finished()), this, SLOT(deleteThread()));
	thread->start();
}
예제 #12
0
파일: uthreads.cpp 프로젝트: shahamran/os
/*
 * Description: This function terminates the thread with ID tid and deletes
 * it from all relevant control structures. All the resources allocated by
 * the library for this thread should be released. If no thread with ID tid
 * exists it is considered as an error. Terminating the main thread
 * (tid == 0) will result in the termination of the entire process using
 * exit(0) [after releasing the assigned library memory]. 
 * Return value: The function returns 0 if the thread was successfully
 * terminated and -1 otherwise. If a thread terminates itself or the main
 * thread is terminated, the function does not return.
*/
int uthread_terminate(int tid)
{
	// Block SIGTVALRM signal
	sigset_t oldSet;
	blockSignal(SIGVTALRM, &oldSet);

	// If main thread is terminated, delete all threads and quit.
	// The deleteThread function checks and manages data for future
	// process run, which is un-needed in this point.
	if (tid == MAIN_THREAD_ID)
	{
		for (auto th : livingThreads)
		{
			delete th.second;
		}
		exit(EXIT_SUCC);
	}
	// If no such thread exists, return failure.
	if (livingThreads.find(tid) == livingThreads.end())
	{
		std::cerr << LIB_ERROR_MSG <<"terminate(" << tid 
			  << ") failed - no such thread id" << std::endl;
		resetSigMask(&oldSet);
		return EXIT_FAIL;
	}

	// Otherwise, delete thread tid, if it's not sleeping.
	if (livingThreads[tid]->get_state() == uthread::state::SLEEPING)
	{
		std::cerr << LIB_ERROR_MSG
		          << "can't terminate a sleeping thread" << std::endl;
		resetSigMask(&oldSet);
		return EXIT_FAIL;
	}
	// If deleted yourself, goto contextSwitch.
	if ((uthread::id)tid == currentThread)
	{
		// Set this tid as the one that needs to be deleted
		// in the next contextSwitch
		toDelete = tid;
		resetSigMask(&oldSet);
		contextSwitch(SIGVTALRM);
		return EXIT_SUCC; // This should not be reached
	}
	// Otherwise, delete and return
	else
	{
		// Unblock SIGVTALRM and return
		resetSigMask(&oldSet);
		deleteThread(tid);
		return EXIT_SUCC;
	}
}
예제 #13
0
END_TEST

/*
\begin{test}{SIGRAPH0502}
  \TestDescription{Schedule inheritance graph: thread deletion test}
  \TestImplementationProcess{
    Delete thread 1 and thread 6, effective priority of main thread should be 5.
  }
  \TestPassStatus{pass}
  \TestImplementationStatus{Implemented}
  \TestRegressionStatus{In regression test suite}
\end{test}
*/
START_TEST(SIGRAPH0502)
{
    setup_graph();
    deleteThread(prio1_thread);
    prio1_thread = L4_nilthread;
    deleteThread(prio6_thread);
    prio6_thread = L4_nilthread;
    measure_effective_prio(5);
    delete_all();
}
예제 #14
0
파일: smt.c 프로젝트: BruceYi/okl4
END_TEST

/*
\begin{test}{SMT0301}
  \TestDescription{Thread creation and deletion of receiving thread}
  \TestFunctionalityTested{Global scheduler, thread creation and deletion}
  \TestImplementationProcess{
    The following process is repeated:
    \begin{enumerate}
      \item Five receiving threads are created. All threads are scheduled across all
    available hardware threads. 
    \item The threads are then deleted.
      \end{enumerate}
    The main threads are constrained to running on hardware thread 0.
}
  \TestImplementationStatus{Implemented}
  \TestIsFullyAutomated{Yes}
  \TestRegressionStatus{In regression test suite}
  \TestNotes{Hardware constraint specification is only used on supported
    architectures. For others, the threads will execute round robin.}
    \TestSeeAlso{See document \emph{L4 SMT Support} 10020:2005}
\end{test}
*/
START_TEST(SMT0301)
{
    int i, j;
    L4_ThreadId_t rthread[5];

    pingpong_cleanup = 0;

    changeThreadCreationSMTBitmask(63);

    for (j=0;j<TEST3_MAJOR_ITERATIONS;j++) {
        for (i=0;i<5;i++)
            rthread[i] = createThreadInSpace(L4_nilthread, (void *)synch_recv);

        /* Give threads time to start up or our pager may complain
         *  about us going away.
         */
        L4_ThreadSwitch(main_thread);
        sleep_a_bit();
        L4_ThreadSwitch(main_thread);

        for (i=0;i<5;i++)
            deleteThread(rthread[i]);
    }


}
예제 #15
0
파일: thread.cpp 프로젝트: autotrad/apery
void ThreadPool::readUSIOptions(Searcher* s) {
	maxThreadsPerSplitPoint_ = s->options["Max_Threads_per_Split_Point"];
	const size_t requested   = s->options["Threads"];
	minimumSplitDepth_ = (requested < 6 ? 4 : (requested < 8 ? 5 : 7)) * OnePly;

	assert(0 < requested);

	while (size() < requested)
		push_back(newThread<Thread>(s));

	while (requested < size()) {
		deleteThread(back());
		pop_back();
	}
}
예제 #16
0
파일: uthreads.cpp 프로젝트: shahamran/os
/**
 * Function: contextSwitch
 * The scheduling function for this library.
 * This function is the handler for SIGVTALRM signal.
 * In charge of switching between threads, incrementing the quanta count and
 * maintaining the READY list.
 * This function returns only when the next thread starts running.
 * Note that SIGVTALRM is blocked by default since this is its handler.
 */
void contextSwitch(int)
{
	// Stop the timer to prevent SIGVRALRM aggregation - i.e. if this
	// func. is reached before the timer ended, we don't want the timer
	// to send another signal (which will be blocked) while in this
	// function.
	stopTimer();

	// Useful current thread pointer
	// everywhere in this function, curr holds a pointer to the currently
	// discussed thread, and it changes throughout the function.
	uthread *curr = livingThreads[currentThread];

	// Save current thread's environment
	int ret_val = sigsetjmp(curr->env, SAVE_SIGS);
	// If you came here from siglongjmp, go away!
	if (ret_val == LONGJMP_VAL)
	{
		// If the last thread tried to terminate itself,
		// Finish the job. Now.
		deleteThread(toDelete);
		toDelete = MAIN_THREAD_ID;
		return;
	}

	// Self explanatory
	++totalQuanta;
	wakeSleepingThreads();

	// If the thread stopped because of quantum end,
	// add it to the READY list
	if (curr->get_state() == uthread::state::RUNNING)
	{
		curr->set_state(uthread::state::READY);
		readyThreads.push_back(currentThread);
	}

	// Switch to the next READY thread
	currentThread = readyThreads.front();
	readyThreads.pop_front();
	curr = livingThreads[currentThread];
	curr->set_state(uthread::state::RUNNING);
	
	// Reset Timer
	resetTimer();
	// Go to next thread.
	siglongjmp(curr->env, LONGJMP_VAL);
}
예제 #17
0
파일: thread.cpp 프로젝트: aoshimanoa/apery
void ThreadPool::readUSIOptions(Searcher* s) {
  maxThreadsPerSplitPoint_ = s->options[OptionNames::MAX_THREADS_PER_SPLIT_POINT];
  const size_t requested = s->options[OptionNames::THREADS];
  minimumSplitDepth_ = (requested < 6 ? 4 : (requested < 8 ? 5 : 7)) * OnePly;

  assert(0 < requested);

  while (size() < requested) {
    push_back(newThread<Thread>(s));
  }

  while (requested < size()) {
    deleteThread(back());
    pop_back();
  }
}
예제 #18
0
void UploadInfoThread::start()
{
	deleteThread();
	m_bStarted = true;

	m_pThread = new UploadThread(m_pUploadThreadInfo);

	m_pThread->onPauseEvent += delegate(this, &UploadInfoThread::onPause);
	m_pThread->onUnpauseEvent += delegate(this, &UploadInfoThread::onUnpause);

	m_pThread->onCompleteEvent += delegate(&onCompleteEvent);
	m_pThread->onUploadProgressEvent += delegate(&onUploadProgressEvent);
	m_pThread->onErrorEvent += delegate(&onErrorEvent);

	m_pThread->setWebCore(m_pWebCore);
	m_pThread->setUserCore(m_pUser);
	m_pThread->setUpLoadManager(m_pUploadManager);

	m_pThread->start();
}
예제 #19
0
파일: mutex.c 프로젝트: BruceYi/okl4
END_TEST

/*
\begin{test}{MUTEX0301}
  \TestDescription{Verify unprivileged thread can not delete mutex}
  \TestFunctionalityTested{\Func{L4\_DeleteMutex}}
  \TestImplementationProcess{
    \begin{enumerate}
        \item Create a mutex.
        \item Create unprivileged thread.
        \item Unprivileged thread call \Func{L4\_DeleteMutex} with the created mutex.
        \item Checks \Func{L4\_DeleteMutex} returns an error.
    \end{enumerate}
  }
  \TestPassStatus{pass}
  \TestImplementationStatus{Implemented}
  \TestRegressionStatus{In regression test suite}
\end{test}
*/
START_TEST(MUTEX0301)
{
    L4_ThreadId_t unpriv_thread;
    L4_MsgTag_t tag;
    L4_Word_t res;

    res = okl4_kmutexid_allocany(mutexid_pool, &m);
    fail_unless(res == OKL4_OK, "Failed to allocate any mutex id.");
    res = L4_CreateMutex(m);
    fail_unless(res == 1, "L4_CreateMutex() failed");
    unpriv_thread = createThreadInSpace(L4_nilspace, create_delete_mutex_thread);
    L4_Set_Label(&tag, 0xd);
    L4_Set_MsgTag(tag);
    L4_Call(unpriv_thread);

    res = L4_DeleteMutex(m);
    fail_unless(res == 1, "L4_DeleteMutex() failed");
    okl4_kmutexid_free(mutexid_pool, m);
    deleteThread(unpriv_thread);
}
예제 #20
0
/*
 * This function processes the action for a Dragon
 * first the function asks the user to enter the name of a Dragon.
 *
 * This name, along with the Dragon array is passed to the selectDragon
 * function. If the index returned from the selectDragon function is not
 * -1, then we have the index number in the array of the requested Dragon.
 *
 *  The user is then asked to enter a direction
 *
 *  left, right, up or down
 *
 *  The position of the selected Dragon is updated, using the
 *  appropriate function in the util.cpp file and the set function in the
 *  Dragon class.
 *
 *  After the Dragon position is updated, this function then checks
 *  whether the Dragon is close enough to destroy the PernThread object,
 *  using the flameThread function that you have implemented in the
 *  util.cpp file.
 *
 *  If the PernThread is destroyed, then the PernThread object is deleted
 *  (remembering to set the ptPtr to nullptr)
 *  and an appropriate congratulatory message is displayed to the screen.
 *
 *  If the PernThread is not destroyed, then the PernThread object has its
 *  position updated, again using the appropriate function in the util.cpp
 *  file.
 *
 *  After this update, this function checks whether or not the Y position
 *  of the PernThread object is 0 or not.
 *
 *  If the Y position is 0 then the PernThread object has reached the
 *  ground. An appropriate warning message should be displayed to the
 *  screen, the PernThread object is deleted again remembering to set
 *  ptPtr ot nullptr.
 *
 */
void action(Dragon * dragons, int currentDragonNumbers, PernThread *& ptPtr)
{
	cout << "First select a Dragon" << endl;
	int index = selectDragon(dragons, currentDragonNumbers);
	if (-1 == index)
	{
		cout << "Dragon isn't exist" << endl;
		return;
	}

	string direction;
	
	while (true)
	{
		cout << "Enter direction (left, right, up, down) >> ";
		getline(cin, direction);
		if (direction == "left")
		{
			dragons[index].setNewPosX(dragonNewXPos(dragons[index], false));
		}
		else if (direction == "right")
		{
			dragons[index].setNewPosX(dragonNewXPos(dragons[index], true));
		}
		else if (direction == "up")
		{
			dragons[index].setNewPosY(dragonNewYPos(dragons[index], true));
		}
		else if (direction == "down")
		{
			dragons[index].setNewPosY(dragonNewYPos(dragons[index], false));
		}
		else
		{
			cout << "Invalid input" << endl;
			continue;
		}

		break;
	}

	if (nullptr == ptPtr)
		return;

	if (flameThread(dragons[index], ptPtr))
	{
		deleteThread(ptPtr);
		cout << "Congratulations Rider " << dragons[index].getRiderName()
			<< " and Dragon " << dragons[index].getDragonName() << "!!!!!"
			<< "You have successfully destroyed this Thread" << endl
			<< "More thread is on the way, stay alert!!" << endl;
	}
	else
	{
		threadNewPos(ptPtr);
		if (ptPtr->getCurrentYPos() == 0)
		{
			deleteThread(ptPtr);
			cout << "Try harder next time riders!!!" << endl
				<< "You must not let Thread reach the ground!" << endl;
		}

	}

	//TODO
}
예제 #21
0
UploadInfoThread::~UploadInfoThread()
{
	deleteThread();
	safe_delete(m_pUploadThreadInfo);
}