Пример #1
0
int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
	HANDLE child_thread(::CreateThread(0, 0, &thread_proc, nullptr, 0, nullptr));
	::WaitForSingleObject(child_thread, INFINITE);
	::CloseHandle(child_thread);
	return 0;
}
Пример #2
0
/* Start children. They will initialize and then block until work is ready.
 */
void init_threads(uint64_t pmin, void (*fun)(uint64_t))
{
  int i, pid;

  if (pipe(primes_pipe) < 0 || pipe(factors_pipe) < 0)
    error("pipe() failed.");

  parcel_len = 0;
  for (i = 0; i < num_children; i++)
    hightide[i] = pmin;

  signal(SIGCHLD,handle_sigchld); /* SIGCHLD is ignored by default. */

  for (i = 0; i < num_children; i++)
  {
    if ((pid = fork()) < 0) /* Error */
    {
      error("fork() failed.");
    }
    else if (pid == 0) /* Child process */
    {
      child_num = i;
      child_thread(fun);
    }
    else /* Parent process */
    {
      child_pid[i] = pid;
      if (verbose_opt)
        report(1,"Child thread %d started, pid=%d.",i,pid);
    }
  }

  close(primes_pipe[0]);
  close(factors_pipe[1]);
}