• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <pthread.h>
2 #include <string.h>
3 #include "test.h"
4 #include <stdio.h>
5 #include <errno.h>
6 #include <unistd.h>
7 
8 #define TEST(c, ...) ((c) ? 1 : (t_error(#c" failed: " __VA_ARGS__),0))
9 
pthread_test(void * arg)10 void* pthread_test(void* arg)
11 {
12     *((pid_t *)arg) = gettid();
13     return NULL;
14 }
15 
main(int argc,char const * argv[])16 int main(int argc, char const *argv[])
17 {
18     TEST(gettid() == pthread_gettid_np(pthread_self()),"pthread_gettid_np() is failed\n");
19 
20     pid_t tid;
21     pthread_t t;
22     pthread_create(&t,NULL,pthread_test,&tid);
23     pid_t recv_result = pthread_gettid_np(t);
24     TEST(0 == pthread_join(t,NULL),"pthread_join is failed\n");
25 
26     TEST(tid == recv_result,"the tid of pthread or tid of pthread_gettid_np() is wrong\n");
27     return 0;
28 }