Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mainthreadexits.c « pthread « winsup.api « testsuite « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b3a3653b8fe58648d8e0eb5bceefbc1abb856593 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>

static void * Thread (void *);

static pthread_t main_thread;
static pthread_t secondThread;
static int result = 2;

int main(void)
{
  main_thread = pthread_self ();

  if (pthread_create (&secondThread, NULL, Thread, NULL))
      exit (1);
  sleep (5);
  pthread_exit (&result);
  /* If pthread_exit doesm't (which would be a bug) then we do */
  return 1;
}

static void * Thread (void *not_used)
{
  void *myresult;
  /* We should be able to join this */
  if (pthread_join (main_thread, &myresult))
      exit (1);

  if (*(int *)myresult != 2)
      exit (1);

  exit (0);
}
/*
This valid code doesn't work at all. The mainthread object in MTinterface
is not properly initialized, the cancel_event is NULL and the win32_obj_id
is NULL because myself->hProcess is NULL when MTinterface is initialized
(and i don't think that a process handle can be used as thread handle).
Even if the handles would be valid the pthread_join call would try to
delete a thread object that is created static which would result in a
corrupted heap.

Concept test Contributed by Thomas Pfaff <tpfaff@gmx.net>
Scriptable test by Robert Collins <rbtcollins@hotmail.com>

*/