1 #include "../../config.h"
11 #ifdef HAVE_ASM_UNISTD_H
12 #include <asm/unistd.h> // __NR_gettid
17 static int s_debug
= 0;
23 return syscall(__NR_gettid
);
29 static void print_thread_id(const char* const label
)
34 snprintf(msg
, sizeof(msg
),
35 "%spid %ld / kernel thread ID %d / Valgrind thread ID %d\n",
36 label
, (long) getpid(), getktid(), DRD_GET_VALGRIND_THREADID
);
37 write(STDOUT_FILENO
, msg
, strlen(msg
));
41 static void SignalHandler(const int iSignal
)
43 print_thread_id("Signal was delivered to ");
46 void* thread_func(void* thread_arg
)
48 print_thread_id("thread: ");
51 //assert(result < 0 && errno == EINTR);
56 int main(int argc
, char** argv
)
59 struct timespec tsDelay
;
61 // Primitive argument parsing.
65 print_thread_id("main: ");
69 memset(&sa
, 0, sizeof(sa
));
70 sa
.sa_handler
= &SignalHandler
;
71 sigemptyset(&sa
.sa_mask
);
72 sigaction(SIGALRM
, &sa
, 0);
75 if (pthread_create(&threadid
, 0, thread_func
, 0) != 0) {
76 fprintf(stderr
, "Thread creation failed\n");
79 // Wait until the thread is inside clock_nanosleep().
81 tsDelay
.tv_nsec
= 20 * 1000 * 1000;
82 nanosleep(&tsDelay
, 0);
83 // And send SIGALRM to the thread.
84 pthread_kill(threadid
, SIGALRM
);
85 pthread_join(threadid
, 0);