Exemplo n.º 1
0
void test_rwlock(Ardb& db)
{
    WriteTask wtask;
    ReadTask rtask;
    std::map<int, int> mm;
    SpinRWLock lock;
    wtask.lock = &lock;
    wtask.mm = &mm;
    rtask.lock = &lock;
    rtask.mm = &mm;
    Thread* w = new Thread(&wtask);
    std::vector<Thread*> ts;
    for(uint32 i = 0; i < 10; i++)
    {
        Thread* r = new Thread(&rtask);
        r->Start();
        ts.push_back(r);
    }
    w->Start();
    w->Join();
    std::vector<Thread*>::iterator tit = ts.begin();
    while(tit != ts.end())
    {
        (*tit)->Join();
        tit++;
    }
    INFO_LOG("mm size=%u", mm.size());
}
Exemplo n.º 2
0
void ovrJobThread::Shutdown()
{
	OVR_ASSERT( Jni == nullptr );	// DetachFromCurrentThread should have been called first
	OVR_ASSERT( MyThread != nullptr );

	MyThread->Join();

	delete MyThread;	// this will call Join()
	MyThread = nullptr;	
}
Exemplo n.º 3
0
      /**
       * \brief Test the creation and join of thread. 
       */
      void testThreadCreate()
      {
        void* ret = NULL;
        Callback obj;
        Thread th = Thread(new ThreadArgImpl<Callback>(obj, &Callback::Call, NULL));

        th.Start(false);
        th.Join(&ret);

        CPPUNIT_ASSERT(ret == (void*)0xABCD);
      }
Exemplo n.º 4
0
	void Program::Run()
	{
		Thread* th = new Thread(new ThreadStart(DELEGATE_FUNC(Program::target1)));
		Thread* th2 = new Thread(new ThreadStart(DELEGATE_FUNC(Program::target2)));
		Console::WriteLine(new String("Start threads"));
		th->Start();
		th2->Start();
		Thread::Sleep(5000);
		Console::WriteLine(new String("Abort Target 2"));
		th2->Abort();
		Console::WriteLine(new String("Wait for Target 1 to finish (15 iterations)"));
		th->Join();
		Console::WriteLine(new String("Finished"));
	}
Exemplo n.º 5
0
void JobManager::Shutdown()
{
	m_running = false;
	while (m_threads.size() > 0) {
		Thread* thread = m_threads.front();
		thread->Join();
		delete thread;

		m_threads.pop_front();
	}

	// finish out finished jobs
	Update();
}
Exemplo n.º 6
0
Arquivo: main.cpp Projeto: lhmouse/MCF
int __stdcall dlltest(int a, int b) noexcept {
	auto f = [](Utf8String s){
		std::printf("thread %u: tls = %s\n", (unsigned)::GetCurrentThreadId(), GetString().GetStr());
		GetString() = std::move(s);
		std::printf("thread %u: tls = %s\n", (unsigned)::GetCurrentThreadId(), GetString().GetStr());
	};

	Thread t;
	t.Create(Bind(f, "world"_u8s), false);
	f("hello"_u8s);
	t.Join();

	return a + b;
}
Exemplo n.º 7
0
      /**
       * \brief Test the cancelation of thread. 
       */
      void testThreadCancel()
      {
        void* ret = NULL;
        Callback obj;
        Thread th = Thread(new ThreadArgImpl<Callback>(obj, &Callback::Call2, NULL));

        th.Start(false);
        th.Stop();
        th.Join(&ret);
        
        /* on x86 it returns 0xffffffff
         * on x86-64 0xffffffffffffffff
         * so (void*)-1
         */
        CPPUNIT_ASSERT(ret == (void*)-1);
      }
Exemplo n.º 8
0
int main(){
	signal(SIGHUP, HTTPServer::HUP_received);

	Config* con = Config::Instance();
	con->saveParam();
	int Port = atoi(con->lookupParam("Port").c_str());
	cerr << "opening a socket" << endl;
	Socket* masterSocket = new Socket();
	if (masterSocket->Listen(Port) < 0) { 
		// handle error
		cerr << "Error: the listen function has failed, OS cannot accept new connection" << endl; 
		return -1;
	}

	int LENGTH = 2;
	int count = 0;
	Thread* threads[LENGTH];
	for (int i = 0; i < LENGTH; i++)
		threads[i] = NULL;

	ssbuf* ssbuffer;
	Thread* thread;

	Thread* threadWatch = new Thread();
	threadWatch->Run(new ServWatcher(thread));

	MutexInstance::Instance();

	while ((ssbuffer = new ssbuf())->accept(masterSocket) != 0) {
		cout << (threads[count] == NULL) << endl;
		if (threads[count] == NULL) {
			cout << "created new" << endl;
			threads[count] = new Thread();
		}
		thread = threads[count];
		cout << "Opening new connection:"<<count<<endl;

		thread->Join();
		cout << "Joining"<<endl;
		cout << "Run:"<<thread->Run(new HTTPServer(thread, ssbuffer, masterSocket))<<endl;
		cout << "Running:"<<count<<endl;
		if (count++ > LENGTH-1)
			count = 0;
		if (HTTPServer::server_count <= 0) break;
	}
	return 0;
}
Exemplo n.º 9
0
int ThreadPool::CancelAll() {
    int ret = 0;
    ThreadVec::iterator it = threads.end();
    while (it != threads.begin()) {
	it --;
	Thread *t = *it;
	if (t->Cancel() == -1 || t->Join() == -1) {
	    ret = -1;
	    break;
	}

	delete t;
	it = threads.erase(it);
    }
    
    return ret;
}
Exemplo n.º 10
0
/**
 * Starts an Interactive simulation session
 * the runtime waits until a user shuts down the simulation
 */
int startInteractiveSimulation(int argc, char**argv, void* data)
{
  int retVal = -1;

  // ppriv - NO_INTERACTIVE_DEPENDENCY - for simpler debugging in Visual Studio
#ifndef NO_INTERACTIVE_DEPENDENCY
  initServiceInterfaceData(argc, argv, data);

  //Create the Control Server Thread
  Thread *threadSimulationControl = createControlThread();
  threadSimulationControl->Join();
  delete threadSimulationControl;

  std::cout << "simulation finished!" << std::endl;
#else
  std::cout << "Interactive Simulation not supported when LEAST_DEPENDENCY is defined!!!" << std::endl;
#endif
  return retVal; //TODO 20100211 pv return value implementation / error handling
}
Exemplo n.º 11
0
void ThreadPoolImpl::Destroy()
{
	if (!m_bCreate) {
		return;
	}

	do
	{
		//!should wait dead thread have been deleted.
		unsigned int nThread = 0, nTask = 0;
		this->Statistic(nThread, nTask);
		if (m_nMinThread == nThread && 0 == nTask) {
			break;
		}
		else {
			Thread::Sleep(10);
		}

	} while (1);

	TAutoLock lock(m_mtxThread);
	ThreadIterator itr = m_threads.begin();
	while (itr != m_threads.end())
	{
		//!should wait all thread have been done.
		Thread   *pThread = (*itr);
		Runnable *pWorker = pThread->GetRunnable();
		pWorker->Stop();
		pThread->Join();
		delete pThread;
		(*itr) = 0;
		m_threads.erase(itr);
		itr = m_threads.begin();
	}

	//!now, there should be no task.
	assert(m_tasks.empty());
	m_bCreate = false;
}
Exemplo n.º 12
0
int main ()
{
  printf ("Results of mutex_test:\n");

  try
  {
    LogFilter filter ("system.threads.*", &print_log);

    printf ("create mutex\n");

    Mutex mutex_holder;

    mutex = &mutex_holder;

    printf ("lock mutex\n");

    mutex->Lock ();

    printf ("create thread\n");

    Thread thread (&run);

    while (!flag);

    printf ("unlock mutex\n");

    mutex->Unlock ();

    thread.Join ();

    printf ("exit\n");
  }
  catch (std::exception& exception)
  {
    printf ("exception: %s\n", exception.what ());
  }

  return 0;
}
Exemplo n.º 13
0
		void JoinThread() {
			WAWO_ASSERT( m_thread != NULL );
			if(m_thread->Joinable()) {
				m_thread->Join();
			}
		}
Exemplo n.º 14
0
	/// Join timer thread. Wait till exits.
   void join() { _thread.Join(); }