Esempio n. 1
0
void
Thread::Join()
{
  assert(IsDefined());
  assert(!IsInside());

#ifdef HAVE_POSIX
  pthread_join(handle, nullptr);
  defined = false;
#else
  ::WaitForSingleObject(handle, INFINITE);
  ::CloseHandle(handle);
  handle = nullptr;
#endif

#ifndef NDEBUG
  all_threads_mutex.lock();
  all_threads.erase(all_threads.iterator_to(*this));
  all_threads_mutex.unlock();
#endif
}
Esempio n. 2
0
bool
Thread::Join(unsigned timeout_ms)
{
  assert(IsDefined());
  assert(!IsInside());

  bool result = ::WaitForSingleObject(handle, timeout_ms) == WAIT_OBJECT_0;
  if (result) {
    ::CloseHandle(handle);
    handle = nullptr;

#ifndef NDEBUG
    {
      all_threads_mutex.lock();
      all_threads.erase(all_threads.iterator_to(*this));
      all_threads_mutex.unlock();
    }
#endif
  }

  return result;
}