diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/self1.c (renamed from tests/self.c) | 0 | ||||
| -rw-r--r-- | tests/self2.c | 31 | ||||
| -rw-r--r-- | tests/self3.c | 34 | 
3 files changed, 65 insertions, 0 deletions
| diff --git a/tests/self.c b/tests/self1.c index 0addfc8..0addfc8 100644 --- a/tests/self.c +++ b/tests/self1.c diff --git a/tests/self2.c b/tests/self2.c new file mode 100644 index 0000000..76d7b71 --- /dev/null +++ b/tests/self2.c @@ -0,0 +1,31 @@ +#include <pthread.h> +/* Hack. Peer into implementation details. */ +#include <implement.h> +#include <assert.h> +#include <stdio.h> + +void * +entry(void * arg) +{ +  /* Like systems such as HP-UX, we can't print the value of the thread ID +     because it's not an integral type. Instead, we'll poke our noses into +     the pthread_t structure and dump a useful internal value. This is +     ordinarily bad, m'kay? */ + +  pthread_t t = pthread_self(); +  printf("my thread is %lx\n", t->win32handle);  +  return arg; +} + +int +main() +{ +  int rc; +  pthread_t t; + +  rc = pthread_create(&t, NULL, entry, NULL); +  assert(rc == 0); + +  Sleep(2000); +  return 0; +} diff --git a/tests/self3.c b/tests/self3.c new file mode 100644 index 0000000..17d5ed3 --- /dev/null +++ b/tests/self3.c @@ -0,0 +1,34 @@ +#include <pthread.h> +/* Hack. Peer into implementation details. */ +#include <implement.h> +#include <assert.h> +#include <stdio.h> + +void * +entry(void * arg) +{ +  /* Like systems such as HP-UX, we can't print the value of the thread ID +     because it's not an integral type. Instead, we'll poke our noses into +     the pthread_t structure and dump a useful internal value. This is +     ordinarily bad, m'kay? */ + +  pthread_t t = pthread_self(); +  printf("thread no. %d has id %lx\n", (int) arg, t->win32handle);  +  return 0;  +} + +int +main() +{ +  int rc; +  pthread_t t[2]; + +  rc = pthread_create(&t[0], NULL, entry, (void *) 1); +  assert(rc == 0); + +  rc = pthread_create(&t[1], NULL, entry, (void *) 2); +  assert(rc == 0); + +  Sleep(2000); +  return 0; +} | 
