Example #1
0
int
gl_thread_exit_func (void *retval)
{
  gl_thread_t thread = gl_thread_self ();
  thread->result = retval;
  _endthreadex (0); /* calls ExitThread (0) */
  abort ();
}
Example #2
0
int
main ()
{
  /* Check that gl_thread_self () can be used with just $(LIBTHREAD), not
     $(LIBMULTITHREAD), i.e. in libraries that are multithread-safe but don't
     create threads themselves.  */
  main_thread = gl_thread_self ();

  return 0;
}
int
main ()
{
  main_thread_before = gl_thread_self ();

  if (glthread_create (&worker_thread, worker_thread_func, NULL) == 0)
    {
      void *ret;

      /* Check that gl_thread_self () has the same value before than after the
         first call to gl_thread_create ().  */
      main_thread_after = gl_thread_self ();
      ASSERT (memcmp (&main_thread_before, &main_thread_after,
                      sizeof (gl_thread_t))
              == 0);

      gl_thread_join (worker_thread, &ret);

      /* Check the return value of the thread.  */
      ASSERT (ret == &dummy);

      /* Check that worker_thread_func () has finished executing.  */
      ASSERT (work_done);

      return 0;
    }
  else
    {
#if USE_POSIX_THREADS || USE_SOLARIS_THREADS || USE_PTH_THREADS || USE_WINDOWS_THREADS
      fputs ("glthread_create failed\n", stderr);
      return 1;
#else
      fputs ("Skipping test: multithreading not enabled\n", stderr);
      return 77;
#endif
    }
}
Example #4
0
int
glthread_join_func (gl_thread_t thread, void **retvalp)
{
  if (thread == NULL)
    return EINVAL;

  if (thread == gl_thread_self ())
    return EDEADLK;

  if (WaitForSingleObject (thread->handle, INFINITE) == WAIT_FAILED)
    return EINVAL;

  if (retvalp != NULL)
    *retvalp = thread->result;

  DeleteCriticalSection (&thread->handle_lock);
  CloseHandle (thread->handle);
  free (thread);

  return 0;
}