summaryrefslogtreecommitdiff
path: root/tests/self2.c
blob: 83339f10122325f8bc1876d51590b17269b63f12 (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
/*
 * self2.c
 *
 * Test for pthread_self().
 *
 * Depends on API functions:
 *	pthread_create()
 *	pthread_self()
 *
 * Implicitly depends on:
 *	pthread_getspecific()
 *	pthread_setspecific()
 */

#include "test.h"
#include <string.h>

static pthread_t me;

void *
entry(void * arg)
{
  me = pthread_self();

  return arg;
}

int
main()
{
  pthread_t t;

  assert(pthread_create(&t, NULL, entry, NULL) == 0);

  Sleep(2000);

  /*
   * Not much more we can do here but bytewise compare t with
   * what pthread_self returned.
   */
  assert(t == me);
  assert(memcmp((const void *) t, (const void *) me, sizeof t) == 0);

  /* Success. */
  return 0;
}